Skip to content

Commit

Permalink
Remove structopt reference, use Clap helper for verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed Mar 11, 2024
1 parent 2582d7d commit bd47f85
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions shell/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license.workspace = true
edition.workspace = true

[dependencies]
clap-verbosity-flag = "2"
directories.workspace = true
exitcode = "1.1"
owo-colors = "4"
Expand Down
23 changes: 4 additions & 19 deletions shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct Options {
login: bool,

/// Set the verbosity level
#[arg(short = 'v', long = "verbose", action = clap::ArgAction::Count)]
verbosity: u8,
#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity,

/// Silence all output
#[arg(short = 'q', long = "quiet")]
Expand All @@ -52,33 +52,18 @@ struct Options {
/// In private mode, session history is kept independent from other sessions
/// and is stored only in memory. All history generated during a private
/// session will be forgotten when the session terminates.
#[structopt(long = "private")]
#[arg(long = "private")]
private: bool,
}

impl Options {
fn log_level_filter(&self) -> log::LevelFilter {
if self.quiet {
log::LevelFilter::Off
} else {
match self.verbosity {
0 => log::LevelFilter::Warn,
1 => log::LevelFilter::Info,
2 => log::LevelFilter::Debug,
_ => log::LevelFilter::Trace,
}
}
}
}

/// Entrypoint of the program. This just does some boring setup and teardown
/// around the real main body of the program.
fn main() {
// Parse command line args.
let options = Options::parse();

// Initialize logging.
logger::init(options.log_level_filter());
logger::init(options.verbose.log_level_filter());
log_panics::init();

// Create a single-threaded Tokio runtime, which drives the async Riptide
Expand Down

0 comments on commit bd47f85

Please sign in to comment.