summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-11-10 17:37:24 -0600
committerToby Vincent <tobyv13@gmail.com>2022-11-10 17:37:24 -0600
commit4cac42d2299cecdc3d6a7f6d7661137da338278b (patch)
tree4b1954cd32eb54b170616b41f0c43b46f6647722 /src/cli.rs
parentc8681e50194855a2ad36bf984866a30cfcfb8ec9 (diff)
feat: add paths module and tests
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs41
1 files changed, 28 insertions, 13 deletions
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<PathBuf>,
- /// Add additional directory to search results. Can be specified multiple times
- #[arg(short, long)]
- pub(crate) directory: Vec<PathBuf>,
-
- #[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<usize>,
- /// 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<String>,
@@ -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(),
}
}
}