Skip to content

Commit 785554d

Browse files
committed
wip: Clap 4
Signed-off-by: Lann Martin <[email protected]>
1 parent 996d50a commit 785554d

File tree

21 files changed

+498
-453
lines changed

21 files changed

+498
-453
lines changed

Cargo.lock

Lines changed: 29 additions & 111 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 = "2"
@@ -125,7 +125,7 @@ async-trait = "0.1"
125125
base64 = "0.22"
126126
bytes = "1"
127127
chrono = "0.4"
128-
clap = "3.2"
128+
clap = "4.5.45"
129129
conformance-tests = { git = "https://github.com/fermyon/conformance-tests", rev = "61f2799f92b5d85f342cc07e3f5dec5cd0a7bc9c" }
130130
ctrlc = { version = "3.4", features = ["termination"] }
131131
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
@@ -9,6 +9,7 @@
99
// - Code should have at least 2 dependents
1010

1111
pub mod arg_parser;
12+
pub mod cli;
1213
pub mod data_dir;
1314
pub mod paths;
1415
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
@@ -44,11 +44,11 @@ pub struct CliArgs {
4444
pub address: SocketAddr,
4545

4646
/// 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
47-
#[clap(long, env = "SPIN_TLS_CERT", requires = "tls-key")]
47+
#[clap(long, env = "SPIN_TLS_CERT", requires = "tls_key")]
4848
pub tls_cert: Option<PathBuf>,
4949

5050
/// 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
51-
#[clap(long, env = "SPIN_TLS_KEY", requires = "tls-cert")]
51+
#[clap(long, env = "SPIN_TLS_KEY", requires = "tls_cert")]
5252
pub tls_key: Option<PathBuf>,
5353

5454
#[clap(long = "find-free-port")]

crates/trigger/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ unsafe-aot-compilation = []
1616

1717
[dependencies]
1818
anyhow = { workspace = true }
19-
clap = { workspace = true, features = ["derive", "env"] }
19+
clap = { workspace = true, features = ["derive", "env", "wrap_help"] }
2020
ctrlc = { workspace = true }
2121
futures = { workspace = true }
2222
sanitize-filename = "0.5"

crates/trigger/src/cli.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
use std::{future::Future, sync::Arc};
1010

1111
use anyhow::{Context, Result};
12-
use clap::{Args, IntoApp, Parser};
12+
use clap::{Args, CommandFactory, Parser};
1313
use spin_app::App;
1414
use spin_common::sloth;
1515
use spin_common::ui::quoted_path;
@@ -41,6 +41,7 @@ pub const SPIN_WORKING_DIR: &str = "SPIN_WORKING_DIR";
4141
/// A command that runs a TriggerExecutor.
4242
#[derive(Parser, Debug)]
4343
#[clap(
44+
styles = spin_common::cli::CLAP_STYLES,
4445
override_usage = "spin [COMMAND] [OPTIONS]",
4546
next_help_heading = help_heading::<T, B::Factors>()
4647
)]
@@ -68,7 +69,6 @@ pub struct FactorsTriggerCommand<T: Trigger<B::Factors>, B: RuntimeFactorsBuilde
6869
long = "disable-cache",
6970
env = DISABLE_WASMTIME_CACHE,
7071
conflicts_with = WASMTIME_CACHE_FILE,
71-
takes_value = false,
7272
)]
7373
pub disable_cache: bool,
7474

@@ -287,9 +287,9 @@ fn warn_if_wasm_build_slothful() -> sloth::SlothGuard {
287287

288288
fn help_heading<T: Trigger<F>, F: RuntimeFactors>() -> Option<&'static str> {
289289
if T::TYPE == <help::HelpArgsOnlyTrigger as Trigger<F>>::TYPE {
290-
Some("TRIGGER OPTIONS")
290+
Some("Trigger Options")
291291
} else {
292-
let heading = format!("{} TRIGGER OPTIONS", T::TYPE.to_uppercase());
292+
let heading = format!("{} Trigger Options", T::TYPE.to_uppercase());
293293
let as_str = Box::new(heading).leak();
294294
Some(as_str)
295295
}

0 commit comments

Comments
 (0)