Skip to content

Commit

Permalink
upgrade to clap v4 (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 authored Jun 2, 2024
1 parent ab5cb00 commit 8d54a12
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 108 deletions.
186 changes: 90 additions & 96 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ serde_json = "1.0"
rsa = "0.9.2"
rand = "0.8.5"
standback = "0.2.17" # required to fix a compilation error on a transient dependency
clap = { version = "3.1.18", features = ["derive", "cargo", "env"] }
clap_complete = "3.2.1"
clap = { version = "4.5.4", features = ["derive", "cargo", "env"] }
clap_complete = "4.5.2"
log = "0.4.19"
stderrlog = "0.6"
cookie = "0.14"
Expand Down
19 changes: 15 additions & 4 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::{Arc, Mutex};

use clap::{clap_derive::ArgEnum, Parser};
use clap::{Parser, Subcommand, ValueEnum};
use clap_complete::Shell;
use secrecy::SecretString;
use std::str::FromStr;
Expand Down Expand Up @@ -127,7 +127,7 @@ pub(crate) struct GlobalArgs {
help = "Specify your encryption passkey."
)]
pub passkey: Option<SecretString>,
#[clap(short, long, arg_enum, default_value_t=Verbosity::Info, help = "Set the log level. Be warned, trace is capable of printing sensitive data.")]
#[clap(short, long, value_enum, default_value_t=Verbosity::Info, help = "Set the log level. Be warned, trace is capable of printing sensitive data.")]
pub verbosity: Verbosity,

#[cfg(feature = "updater")]
Expand Down Expand Up @@ -160,7 +160,7 @@ pub(crate) struct GlobalArgs {
pub danger_accept_invalid_certs: bool,
}

#[derive(Debug, Clone, Parser)]
#[derive(Debug, Clone, Subcommand)]
pub(crate) enum Subcommands {
Debug(DebugCommand),
Completion(CompletionsCommand),
Expand All @@ -177,7 +177,7 @@ pub(crate) enum Subcommands {
QrLogin(QrLoginCommand),
}

#[derive(Debug, Clone, Copy, ArgEnum)]
#[derive(Debug, Clone, Copy, ValueEnum)]
pub(crate) enum Verbosity {
Error = 0,
Warn = 1,
Expand Down Expand Up @@ -223,3 +223,14 @@ impl From<Args> for CodeCommand {
args.code
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn verify_cli() {
use clap::CommandFactory;
Args::command().debug_assert()
}
}
7 changes: 6 additions & 1 deletion src/commands/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use super::*;
#[derive(Debug, Clone, Parser)]
#[clap(about = "Generate shell completions")]
pub struct CompletionsCommand {
#[clap(short, long, arg_enum, help = "The shell to generate completions for.")]
#[clap(
short,
long,
value_enum,
help = "The shell to generate completions for."
)]
pub shell: Shell,
}

Expand Down
6 changes: 1 addition & 5 deletions src/commands/qr_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ where
accounts.len() == 1,
"You can only log in to one account at a time."
);
// FIXME: in clap v4, this constraint can be expressed as a arg group: https://stackoverflow.com/questions/76315540/how-do-i-require-one-of-the-two-clap-options
ensure!(
self.login_url_source.url.is_some() || self.login_url_source.image.is_some(),
"You must provide either a URL with --url or an image file with --image."
);

let mut account = accounts[0].lock().unwrap();

Expand Down Expand Up @@ -80,6 +75,7 @@ where
}

#[derive(Debug, Clone, clap::Args)]
#[group(required = true, multiple = false)]
pub struct LoginUrlSource {
/// The URL that would normally open in the Steam app. This is the URL that the QR code is displaying. It should start with \"https://s.team/...\"
#[clap(long)]
Expand Down

0 comments on commit 8d54a12

Please sign in to comment.