Skip to content

Commit ec065f5

Browse files
committed
Upgrade to Clap 4
Signed-off-by: Brian Hardock <brian.hardock@fermyon.com>
1 parent 9282f24 commit ec065f5

23 files changed

Lines changed: 1024 additions & 666 deletions

File tree

Cargo.lock

Lines changed: 129 additions & 181 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ rust-version = "1.86"
1818
anyhow = { workspace = true }
1919
async-trait = { workspace = true }
2020
bytes = { workspace = true }
21-
# 'deprecated' enables deprecation warnings
22-
clap = { workspace = true, features = ["deprecated", "derive", "env"] }
21+
clap = { workspace = true, features = ["derive", "env", "string", "wrap_help"] }
22+
clap_lex = "0.7.5"
2323
clearscreen = "4"
2424
comfy-table = "7"
2525
command-group = { version = "5", features = ["with-tokio"] }
@@ -132,7 +132,7 @@ async-trait = "0.1"
132132
base64 = "0.22"
133133
bytes = "1"
134134
chrono = "0.4"
135-
clap = "3.2"
135+
clap = "4.6.0"
136136
conformance-tests = { git = "https://github.com/fermyon/conformance-tests", rev = "ffc2c879cdcb3c619c8f95ae8e0b847af8c8247e" }
137137
ctrlc = { version = "3.4", features = ["termination"] }
138138
dialoguer = "0.11"

crates/common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = { workspace = true }
66

77
[dependencies]
88
anyhow = { workspace = true }
9+
clap = { workspace = true }
910
dirs = { workspace = true }
1011
sha2 = { workspace = true }
1112
tempfile = { workspace = true }

crates/common/src/cli.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Common CLI code and constants
2+
3+
use clap::builder::{styling::AnsiColor, Styles};
4+
5+
/// Clap [`Styles`] for Spin CLI and plugins.
6+
pub const CLAP_STYLES: Styles = Styles::styled()
7+
.header(AnsiColor::Yellow.on_default())
8+
.usage(AnsiColor::Green.on_default())
9+
.literal(AnsiColor::Green.on_default())
10+
.placeholder(AnsiColor::Green.on_default());

crates/common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
pub mod arg_parser;
1212
pub mod assert;
13+
pub mod cli;
1314
pub mod data_dir;
1415
pub mod paths;
1516
pub mod sha256;

crates/expressions/src/template.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ mod tests {
9898
let template = Template::new(tmpl).unwrap();
9999
assert!(
100100
template.parts().eq(&expected),
101-
"{:?} -> {:?} != {:?}",
102-
tmpl,
103-
template,
104-
expected,
101+
"{tmpl:?} -> {template:?} != {expected:?}",
105102
);
106103
}
107104
}

crates/trigger-http/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ pub struct CliArgs {
5757
pub address: SocketAddr,
5858

5959
/// The path to the certificate to use for https, if this is not set, normal http will be used. The cert should be in PEM format
60-
#[clap(long, env = "SPIN_TLS_CERT", requires = "tls-key")]
60+
#[clap(long, env = "SPIN_TLS_CERT", requires = "tls_key")]
6161
pub tls_cert: Option<PathBuf>,
6262

6363
/// The path to the certificate key to use for https, if this is not set, normal http will be used. The key should be in PKCS#8 format
64-
#[clap(long, env = "SPIN_TLS_KEY", requires = "tls-cert")]
64+
#[clap(long, env = "SPIN_TLS_KEY", requires = "tls_cert")]
6565
pub tls_key: Option<PathBuf>,
6666

6767
/// Sets the maximum buffer size (in bytes) for the HTTP connection. The minimum value allowed is 8192.

crates/trigger/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ experimental-wasm-features = []
1818

1919
[dependencies]
2020
anyhow = { workspace = true }
21-
clap = { workspace = true, features = ["derive", "env"] }
21+
clap = { workspace = true, features = ["derive", "env", "wrap_help"] }
2222
ctrlc = { workspace = true }
2323
futures = { workspace = true }
2424
sanitize-filename = "0.5"

crates/trigger/src/cli.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{future::Future, sync::Arc};
1212
use anyhow::{Context, Result};
1313
#[cfg(feature = "experimental-wasm-features")]
1414
use clap::ValueEnum;
15-
use clap::{Args, IntoApp, Parser};
15+
use clap::{Args, CommandFactory, Parser};
1616
use spin_app::App;
1717
use spin_common::sloth;
1818
use spin_common::ui::quoted_path;
@@ -45,6 +45,7 @@ pub const SPIN_WORKING_DIR: &str = "SPIN_WORKING_DIR";
4545
/// A command that runs a TriggerExecutor.
4646
#[derive(Parser, Debug)]
4747
#[clap(
48+
styles = spin_common::cli::CLAP_STYLES,
4849
override_usage = "spin [COMMAND] [OPTIONS]",
4950
next_help_heading = help_heading::<T, B::Factors>()
5051
)]
@@ -72,7 +73,6 @@ pub struct FactorsTriggerCommand<T: Trigger<B::Factors>, B: RuntimeFactorsBuilde
7273
long = "disable-cache",
7374
env = DISABLE_WASMTIME_CACHE,
7475
conflicts_with = WASMTIME_CACHE_FILE,
75-
takes_value = false,
7676
)]
7777
pub disable_cache: bool,
7878

@@ -91,7 +91,7 @@ pub struct FactorsTriggerCommand<T: Trigger<B::Factors>, B: RuntimeFactorsBuilde
9191

9292
/// Enable Wasmtime's debug info for Wasm guests, allowing debugging
9393
/// with gdb or lldb.
94-
#[clap(long = "debug-info", takes_value = false)]
94+
#[clap(long = "debug-info")]
9595
pub debug_info: bool,
9696

9797
/// Print output to stdout/stderr only for given component(s)
@@ -330,9 +330,9 @@ fn warn_if_wasm_build_slothful() -> sloth::SlothGuard {
330330

331331
fn help_heading<T: Trigger<F>, F: RuntimeFactors>() -> Option<&'static str> {
332332
if T::TYPE == <help::HelpArgsOnlyTrigger as Trigger<F>>::TYPE {
333-
Some("TRIGGER OPTIONS")
333+
Some("Trigger Options")
334334
} else {
335-
let heading = format!("{} TRIGGER OPTIONS", T::TYPE.to_uppercase());
335+
let heading = format!("{} Trigger Options", T::TYPE.to_uppercase());
336336
let as_str = Box::new(heading).leak();
337337
Some(as_str)
338338
}

0 commit comments

Comments
 (0)