-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afe372a
commit 30ca917
Showing
12 changed files
with
79 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::{ | ||
env, | ||
fs, | ||
path::PathBuf, | ||
}; | ||
|
||
pub const CONFIG_ENV_VAR: &str = "ERDTREE_CONFIG_PATH"; | ||
pub const CONFIG_NAME: &str = ".erdtreerc"; | ||
|
||
pub fn read_config_to_string() -> Option<String> { | ||
env::var_os(CONFIG_ENV_VAR) | ||
.map(PathBuf::from) | ||
.map(fs::read_to_string) | ||
.map(Result::ok) | ||
.flatten() | ||
.or_else(|| { | ||
env::var_os("HOME") | ||
.map(PathBuf::from) | ||
.map(|p| p.join(CONFIG_NAME)) | ||
.map(fs::read_to_string) | ||
.map(Result::ok) | ||
.flatten() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use clap::{Parser, ValueEnum}; | ||
use clap::{FromArgMatches, Parser, ValueEnum}; | ||
use ignore::{ | ||
overrides::{Override, OverrideBuilder}, | ||
WalkBuilder, WalkParallel, | ||
|
@@ -12,13 +12,16 @@ use std::{ | |
usize, | ||
}; | ||
|
||
/// Operations to load in `.erdtree.toml` defaults. | ||
pub mod config; | ||
|
||
/// Defines the CLI. | ||
#[derive(Parser, Debug)] | ||
#[command(name = "erdtree")] | ||
#[command(author = "Benjamin Nguyen. <[email protected]>")] | ||
#[command(version = "1.3.0")] | ||
#[command(about = "erdtree (et) is a multi-threaded filetree visualizer and disk usage analyzer.", long_about = None)] | ||
pub struct Clargs { | ||
pub struct Context { | ||
/// Root directory to traverse; defaults to current working directory | ||
dir: Option<PathBuf>, | ||
|
||
|
@@ -110,7 +113,7 @@ pub enum DiskUsage { | |
Physical, | ||
} | ||
|
||
impl Clargs { | ||
impl Context { | ||
/// Returns reference to the path of the root directory to be traversed. | ||
pub fn dir(&self) -> &Path { | ||
self.dir | ||
|
@@ -169,10 +172,10 @@ impl Clargs { | |
} | ||
} | ||
|
||
impl TryFrom<&Clargs> for WalkParallel { | ||
impl TryFrom<&Context> for WalkParallel { | ||
type Error = Error; | ||
|
||
fn try_from(clargs: &Clargs) -> Result<Self, Self::Error> { | ||
fn try_from(clargs: &Context) -> Result<Self, Self::Error> { | ||
let root = fs::canonicalize(clargs.dir())?; | ||
|
||
fs::metadata(&root).map_err(|e| Error::DirNotFound(format!("{}: {e}", root.display())))?; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.