1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
use std::path::PathBuf;
use clap::{Args, Parser};
use tracing::{metadata::LevelFilter, Level};
#[derive(Debug, Clone, Parser)]
pub struct Config {
/// Update the history file from the current sessions
#[arg(short, long)]
pub update: 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()
}
}
|