Skip to content

Commit 782011f

Browse files
committed
use fs::canonicalize in cli
1 parent 133fa37 commit 782011f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/cli.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clap::{Parser, ValueEnum};
22

3-
use std::{env::current_dir, path::PathBuf};
3+
use std::{env::current_dir, fs, path::PathBuf};
44

55
#[derive(Debug, Parser)]
66
#[command(version = "0.1.0")]
@@ -39,19 +39,21 @@ pub enum Mode {
3939

4040
impl Cli {
4141
pub fn dir(&self) -> PathBuf {
42-
self.dir
43-
.as_ref()
44-
.cloned()
45-
.or_else(|| current_dir().ok())
46-
.expect("Failed to get DIR")
42+
let dir = match &self.dir {
43+
Some(dir) => fs::canonicalize(dir),
44+
None => current_dir(),
45+
};
46+
47+
dir.expect("Failed to get DIR")
4748
}
4849

4950
pub fn target(&self) -> PathBuf {
50-
self.target
51-
.as_ref()
52-
.cloned()
53-
.or_else(|| Some(self.dir().parent()?.to_path_buf()))
54-
.expect("Failed to get TARGET")
51+
let target = match &self.target {
52+
Some(dir) => fs::canonicalize(dir).ok(),
53+
None => self.dir().parent().map(|d| d.to_path_buf()),
54+
};
55+
56+
target.expect("Failed to get TARGET")
5557
}
5658

5759
pub fn parsed() -> Self {

0 commit comments

Comments
 (0)