summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 353c293..657d05d 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,15 +1,18 @@
use clap::{Args, Parser};
+use figment::{providers::Serialized, value, Metadata, Profile, Provider};
+use serde::Serialize;
use std::path::PathBuf;
use tracing_subscriber::{filter::LevelFilter, Layer, Registry};
-use crate::paths::PathEntry;
+use crate::{paths::PathEntry, Config};
/// Simple program to manage projects and ssh hosts using tmux
-#[derive(Parser, Debug)]
+#[derive(Debug, Clone, Default, Parser, Serialize)]
#[command(author, version, about)]
+#[serde(into = "Config")]
pub struct Cli {
/// Path to directories
- pub(crate) path: Vec<PathBuf>,
+ pub(crate) paths: Vec<PathBuf>,
/// Max depth to recurse.
///
@@ -42,25 +45,39 @@ impl Cli {
vec![fmt_layer]
}
+}
- // TODO: replace this with `impl Figment for Cli`
- pub fn as_config(&self) -> crate::paths::Config {
- crate::paths::Config {
- paths: self
- .path
- .iter()
- .cloned()
- .map(|p| PathEntry {
- path: p,
- hidden: self.hidden,
- recurse: self.max_depth,
- })
- .collect(),
+impl From<Cli> for Config {
+ fn from(value: Cli) -> Self {
+ Config {
+ paths: crate::paths::Config {
+ paths: value
+ .paths
+ .iter()
+ .cloned()
+ .map(|p| PathEntry {
+ path: p,
+ hidden: value.hidden,
+ recurse: value.max_depth,
+ })
+ .collect(),
+ },
+ ..Default::default()
}
}
}
-#[derive(Debug, Default, Args)]
+impl Provider for Cli {
+ fn metadata(&self) -> Metadata {
+ Metadata::named("Tmuxr cli provider")
+ }
+
+ fn data(&self) -> figment::error::Result<value::Map<Profile, value::Dict>> {
+ Serialized::defaults(Self::default()).data()
+ }
+}
+
+#[derive(Debug, Default, Clone, Args)]
pub struct Verbosity {
/// Print additional information per occurrence
#[arg(short, long, action = clap::ArgAction::Count, conflicts_with = "quiet")]
@@ -93,7 +110,7 @@ impl From<&Verbosity> for LevelFilter {
#[cfg(test)]
mod tests {
#[test]
- fn test_start() {
+ fn test_cli_parse() {
assert_eq!(1, 1);
}
}