use std::path::PathBuf; use clap::{Args, Parser, Subcommand}; use tracing::{metadata::LevelFilter, Level}; #[derive(Debug, Clone, Parser)] pub struct Config { #[command(subcommand)] pub command: Commands, /// tmux socket-name, equivelent to `tmux -L ` #[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, #[command(flatten)] pub verbosity: Verbosity, } #[derive(Debug, Clone, Subcommand)] pub enum Commands { /// List available session targets List, /// Switch to a specific session, or create it if it does not exist Switch { /// Target session name or ssh host name: String, }, } #[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 { 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::::from(value).into() } }