From 4cac42d2299cecdc3d6a7f6d7661137da338278b Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Thu, 10 Nov 2022 17:37:24 -0600 Subject: feat: add paths module and tests --- src/cli.rs | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'src/cli.rs') diff --git a/src/cli.rs b/src/cli.rs index 77d9ec5..521809e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,24 +2,32 @@ use clap::{Args, Parser}; use std::path::PathBuf; use tracing_subscriber::{filter::LevelFilter, Layer, Registry}; +use crate::paths::PathEntry; + /// Simple program to manage projects and ssh hosts using tmux #[derive(Parser, Debug)] #[command(author, version, about)] pub struct Cli { - /// Path to search recursively for directories + /// Path to directories pub(crate) path: Vec, - /// Add additional directory to search results. Can be specified multiple times - #[arg(short, long)] - pub(crate) directory: Vec, - - #[command(flatten)] - pub verbose: Verbosity, + /// Max depth to recurse. + /// + /// By default, no limit is set. Setting to 0 will only use the supplied directory. + #[arg(short = 'd', long)] + pub(crate) max_depth: Option, - /// Allows traversal into hidden directories when searching + /// Recurse into hidden directories. + /// + /// Include hidden directories when traversing directories. (default: hidden directories + /// are skipped). A Directory is considered to be hidden if its name starts with a `.` + /// sign (dot). If `max-depth` is set to 0, this has no effect (As no recursion happens). #[arg(long)] pub(crate) hidden: bool, + #[command(flatten)] + pub verbose: Verbosity, + /// Connect to ssh host #[arg(short, long)] pub ssh: Option, @@ -36,11 +44,18 @@ impl Cli { } // TODO: replace this with `impl Figment for Cli` - pub fn as_config(&self) -> crate::directories::Config { - crate::directories::Config { - search: self.path.to_owned(), - add: self.directory.to_owned(), - hidden: self.hidden, + pub fn as_config(&self) -> crate::paths::Config { + crate::paths::Config { + paths: self + .path + .to_owned() + .into_iter() + .map(|p| PathEntry { + path: p, + hidden: self.hidden, + recurse: self.max_depth, + }) + .collect(), } } } -- cgit v1.2.3-70-g09d2