diff options
author | Toby Vincent <tobyv13@gmail.com> | 2023-03-18 19:01:16 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2023-03-18 19:01:16 -0500 |
commit | b9890b578d8bcdb0d0a9c12ba3901b4e34514286 (patch) | |
tree | 6efbe30d3dfb5a26c7ea45d29bf357b60eb63015 /src/config.rs | |
parent | 9b4f0bb63002a2657d89c7519697aabe515282b4 (diff) |
feat: impl history file and sorting
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..7745e0b --- /dev/null +++ b/src/config.rs @@ -0,0 +1,57 @@ +use std::path::PathBuf; + +use clap::{Args, Parser}; +use tracing::{metadata::LevelFilter, Level}; + +#[derive(Debug, Clone, Parser)] +pub struct Config { + pub target: Option<String>, + + #[arg(short, long)] + pub list: bool, + + /// tmux socket-name, equivelent to `tmux -L <socket-name>` + #[arg(short = 'L', long, default_value = "ssh")] + pub socket_name: String, + + /// path to history file [default: $XDG_DATA_HOME/sshr/history] + #[arg(short = 'f', long)] + pub history_file: Option<PathBuf>, + + #[command(flatten)] + pub verbosity: Verbosity, +} + +#[derive(Debug, Default, Clone, Args)] +pub struct Verbosity { + /// Print additional information per occurrence. + /// + /// Conflicts with `--quiet`. + #[arg(short, long, global = true, action = clap::ArgAction::Count, conflicts_with = "quiet")] + pub verbose: u8, + + /// Suppress all output. + /// + /// Conflicts with `--verbose`. + #[arg(short, long, global = true, conflicts_with = "verbose")] + pub quiet: bool, +} + +impl From<&Verbosity> for Option<Level> { + fn from(value: &Verbosity) -> Self { + match 1 + value.verbose - u8::from(value.quiet) { + 0 => None, + 1 => Some(Level::ERROR), + 2 => Some(Level::WARN), + 3 => Some(Level::INFO), + 4 => Some(Level::DEBUG), + _ => Some(Level::TRACE), + } + } +} + +impl From<&Verbosity> for LevelFilter { + fn from(value: &Verbosity) -> Self { + Option::<Level>::from(value).into() + } +} |