From 9d80c191d39c1e78784e63c6dea1a903de3f505c Mon Sep 17 00:00:00 2001 From: Fina Wilke Date: Sun, 25 Feb 2024 22:34:34 +0100 Subject: [PATCH] cli: Replace deprecated clap attribute with arg/command --- Cargo.lock | 11 ------- cli/Cargo.toml | 2 +- cli/src/main.rs | 80 ++++++++++++++++++++++++------------------------- 3 files changed, 41 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1714a5c..6978c554 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -591,7 +591,6 @@ dependencies = [ "anstyle", "clap_lex", "strsim", - "terminal_size", ] [[package]] @@ -2828,16 +2827,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "terminal_size" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" -dependencies = [ - "rustix 0.38.31", - "windows-sys 0.48.0", -] - [[package]] name = "termtree" version = "0.4.1" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d95e9a9a..87e732da 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -15,7 +15,7 @@ rand = "0.8.3" # CLI specific dependencies magic-wormhole = { path = "..", features = ["all"] } -clap = { version = "4", features = ["cargo", "derive", "wrap_help"] } +clap = { version = "4", features = ["cargo", "derive", "help"] } clap_complete = "4" env_logger = "0.11" console = "0.15.0" diff --git a/cli/src/main.rs b/cli/src/main.rs index 506dbae7..4b560626 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -58,7 +58,7 @@ fn install_ctrlc_handler( #[derive(Debug, Args)] struct CommonTransferArgs { /// Enable dilation - #[clap(long, alias = "with-dilation")] + #[arg(long, alias = "with-dilation")] with_dilation: bool, } @@ -67,9 +67,9 @@ struct CommonTransferArgs { struct CommonSenderArgs { /// Suggest a different name to the receiver to keep the file's actual name secret. /// Not allowed when sending more than one file. - #[clap(long = "rename", visible_alias = "name", value_name = "FILE_NAME")] + #[arg(long = "rename", visible_alias = "name", value_name = "FILE_NAME")] file_name: Option, - #[clap( + #[arg( index = 1, required = true, num_args = 1.., @@ -83,10 +83,10 @@ struct CommonSenderArgs { #[derive(Debug, Args)] struct CommonLeaderArgs { /// Enter a code instead of generating one automatically - #[clap(long, value_name = "CODE")] + #[arg(long, value_name = "CODE")] code: Option, /// Length of code (in bytes/words) - #[clap(short = 'c', long, value_name = "NUMWORDS", default_value = "2")] + #[arg(short = 'c', long, value_name = "NUMWORDS", default_value = "2")] code_length: usize, } @@ -94,7 +94,7 @@ struct CommonLeaderArgs { #[derive(Debug, Args)] struct CommonReceiverArgs { /// Store transferred file or folder in the specified directory. Defaults to $PWD. - #[clap(long = "out-dir", value_name = "PATH", default_value = ".", value_hint = clap::ValueHint::DirPath)] + #[arg(long = "out-dir", value_name = "PATH", default_value = ".", value_hint = clap::ValueHint::DirPath)] file_path: PathBuf, } @@ -102,7 +102,7 @@ struct CommonReceiverArgs { #[derive(Debug, Args)] struct CommonFollowerArgs { /// Provide the code now rather than typing it interactively - #[clap(value_name = "CODE")] + #[arg(value_name = "CODE")] code: Option, } @@ -110,7 +110,7 @@ struct CommonFollowerArgs { #[derive(Debug, Clone, Args)] struct CommonArgs { /// Use a custom relay server (specify multiple times for multiple relays) - #[clap( + #[arg( long, visible_alias = "relay", action = clap::ArgAction::Append, @@ -119,38 +119,38 @@ struct CommonArgs { )] relay_server: Vec, /// Use a custom rendezvous server. Both sides need to use the same value in order to find each other. - #[clap(long, value_name = "ws://example.org", value_hint = clap::ValueHint::Url)] + #[arg(long, value_name = "ws://example.org", value_hint = clap::ValueHint::Url)] rendezvous_server: Option, /// Disable the relay server support and force a direct connection. - #[clap(long)] + #[arg(long)] force_direct: bool, /// Always route traffic over a relay server. This hides your IP address from the peer (but not from the server operators. Use Tor for that). - #[clap(long, conflicts_with = "force_direct")] + #[arg(long, conflicts_with = "force_direct")] force_relay: bool, } #[derive(Debug, Subcommand)] -#[clap(arg_required_else_help = true)] +#[command(arg_required_else_help = true)] enum ForwardCommand { /// Make the following ports of your system available to your peer - #[clap( + #[command( visible_alias = "open", alias = "server", /* Muscle memory <3 */ )] Serve { /// List of ports to open up. You can optionally specify a domain/address to forward remote ports - #[clap(value_name = "[DOMAIN:]PORT", action = clap::ArgAction::Append, value_hint = clap::ValueHint::Hostname)] + #[arg(value_name = "[DOMAIN:]PORT", action = clap::ArgAction::Append, value_hint = clap::ValueHint::Hostname)] targets: Vec, - #[clap(flatten)] + #[command(flatten)] common: CommonArgs, - #[clap(flatten)] + #[command(flatten)] common_leader: CommonLeaderArgs, }, /// Connect to some ports forwarded to you - #[clap()] + #[command()] Connect { /// Bind to specific ports instead of taking random free high ports. Can be provided multiple times. - #[clap( + #[arg( short = 'p', long = "port", action = clap::ArgAction::Append, @@ -158,14 +158,14 @@ enum ForwardCommand { )] ports: Vec, /// Bind to a specific address to accept the forwarding. Depending on your system and firewall, this may make the forwarded ports accessible from the outside. - #[clap(long = "bind", value_name = "ADDRESS", default_value = "::", value_hint = clap::ValueHint::Other)] + #[arg(long = "bind", value_name = "ADDRESS", default_value = "::", value_hint = clap::ValueHint::Other)] bind_address: std::net::IpAddr, /// Accept the forwarding without asking for confirmation - #[clap(long, visible_alias = "yes")] + #[arg(long, visible_alias = "yes")] noconfirm: bool, - #[clap(flatten)] + #[command(flatten)] common: CommonArgs, - #[clap(flatten)] + #[command(flatten)] common_follower: CommonFollowerArgs, }, } @@ -173,7 +173,7 @@ enum ForwardCommand { #[derive(Debug, Subcommand)] enum WormholeCommand { /// Send a file or a folder - #[clap(visible_alias = "tx")] + #[command(visible_alias = "tx")] Send { #[clap(flatten)] common: CommonArgs, @@ -185,22 +185,22 @@ enum WormholeCommand { common_transfer: CommonTransferArgs, }, /// Receive a file or a folder - #[clap(visible_alias = "rx")] + #[command(visible_alias = "rx")] Receive { /// Accept file transfer without asking for confirmation - #[clap(long, visible_alias = "yes")] + #[arg(long, visible_alias = "yes")] noconfirm: bool, - #[clap(flatten)] + #[command(flatten)] common: CommonArgs, - #[clap(flatten)] + #[command(flatten)] common_follower: CommonFollowerArgs, - #[clap(flatten)] + #[command(flatten)] common_receiver: CommonReceiverArgs, - #[clap(flatten)] + #[command(flatten)] common_transfer: CommonTransferArgs, }, /// Send a file to many recipients - #[clap( + #[command( after_help = "This works by sending the file in a loop with the same code over \ and over again. Note that this also gives an attacker multiple tries \ to guess the code, whereas normally they have only one. This can be \ @@ -212,33 +212,33 @@ enum WormholeCommand { SendMany { /// Only send the file up to n times, limiting the number of people that may receive it. /// These are also the number of tries a potential attacker gets at guessing the password. - #[clap(short = 'n', long, value_name = "N", default_value = "30")] + #[arg(short = 'n', long, value_name = "N", default_value = "30")] tries: u64, /// Automatically stop providing the file after a certain amount of time. - #[clap(long, value_name = "MINUTES", default_value = "60")] + #[arg(long, value_name = "MINUTES", default_value = "60")] timeout: u64, - #[clap(flatten)] + #[command(flatten)] common: CommonArgs, - #[clap(flatten)] + #[command(flatten)] common_leader: CommonLeaderArgs, - #[clap(flatten)] + #[command(flatten)] common_send: CommonSenderArgs, }, /// Forward ports from one machine to another - #[clap(subcommand)] + #[command(subcommand)] Forward(ForwardCommand), /// Generate shell completions for the wormhole CLI - #[clap(hide = true)] + #[command(hide = true)] Completion { /// The shell type to generate completions for (bash, elvish, powershell, zsh) shell: clap_complete::Shell, }, - #[clap(hide = true)] + #[command(hide = true)] Help, } #[derive(Debug, Parser)] -#[clap( +#[command( version, author, about, @@ -251,7 +251,7 @@ enum WormholeCommand { )] struct WormholeCli { /// Enable logging to stdout, for debugging purposes - #[clap( + #[arg( short = 'v', long = "verbose", alias = "log",