diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 76 |
1 files changed, 62 insertions, 14 deletions
diff --git a/src/config.rs b/src/config.rs index 63dfbc7..258255b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,30 +1,78 @@ -use std::path::PathBuf; - use clap::{Args, Parser}; use tracing::{metadata::LevelFilter, Level}; +use crate::{history, session, stdio, tmux}; + #[derive(Debug, Clone, Parser)] pub struct Config { - /// Update the history file from the current sessions - #[arg(short, long)] - pub update: bool, + #[command(flatten)] + pub enabled: Flags, - /// tmux socket-name, equivelent to `tmux -L <socket-name>` - #[arg(short = 'L', long, default_value = "ssh")] - pub socket_name: String, + #[command(flatten)] + pub stdio: stdio::Config, - /// Name of host to exclude - #[arg(short, long)] - pub exclude: Vec<String>, + #[command(flatten)] + pub sessions: session::Config, + + #[command(flatten)] + pub history: history::History, - /// path to history file [default: $XDG_DATA_HOME/sshr/history] - #[arg(short = 'f', long)] - pub history_file: Option<PathBuf>, + #[command(flatten)] + pub tmux: tmux::Tmux, #[command(flatten)] pub verbosity: Verbosity, } +#[derive(Debug, Clone, Args)] +pub struct Flags { + /// Include localhost + #[arg(short, long)] + pub localhost: bool, + + /// Include hosts from tmux session names + #[arg(short, long)] + pub tmux: bool, + + /// Include hosts from history file + #[arg(short = 'H', long)] + pub history: bool, + + /// Include hosts from the ssh `known_hosts` + #[arg(short, long)] + pub ssh: bool, + + /// Include hosts from `/etc/hosts` + #[arg(short = 'o', long)] + pub hosts: bool, + + /// Alias to include all host sources + #[arg(short, long)] + pub all: bool, +} + +impl Flags { + pub fn localhost(&self) -> bool { + self.all || self.localhost + } + + pub fn tmux(&self) -> bool { + self.all || self.tmux + } + + pub fn history(&self) -> bool { + self.all || self.history + } + + pub fn ssh(&self) -> bool { + self.all || self.ssh + } + + pub fn hosts(&self) -> bool { + self.all || self.hosts + } +} + #[derive(Debug, Default, Clone, Args)] pub struct Verbosity { /// Print additional information per occurrence. |