Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to clap 4 #2851

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 20 additions & 84 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
bytes = { workspace = true }
chrono = "0.4"
clap = { version = "3.2.24", features = ["derive", "env"] }
clap = { version = "4", features = ["derive", "env", "string", "wrap_help"] }
clearscreen = "3"
comfy-table = "7"
command-group = "2"
Expand Down
2 changes: 1 addition & 1 deletion crates/componentize/tests/case-helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
anyhow = "1"
clap = { version = "~4.4", features = ["derive", "env"] }
clap = { version = "4.5", features = ["derive", "env"] }
getrandom = "0.2.12"

[workspace]
2 changes: 1 addition & 1 deletion crates/runtime-factors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ llm-cublas = ["spin-factor-llm/llm-cublas"]

[dependencies]
anyhow = { workspace = true }
clap = { version = "3.1.18", features = ["derive", "env"] }
clap = { version = "4", features = ["derive", "env"] }
spin-common = { path = "../common" }
spin-factor-key-value = { path = "../factor-key-value" }
spin-factor-llm = { path = "../factor-llm" }
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime-factors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct TriggerAppArgs {
/// Set a key/value pair (key=value) in the application's
/// default store. Any existing value will be overwritten.
/// Can be used multiple times.
#[clap(long = "key-value", parse(try_from_str = parse_kv))]
#[clap(long = "key-value", value_parser(parse_kv))]
pub key_values: Vec<(String, String)>,

/// Run a SQLite statement such as a migration against the default database.
Expand Down
2 changes: 1 addition & 1 deletion crates/trigger-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ doctest = false
[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
clap = "3"
clap = "4"
futures = { workspace = true }
futures-util = "0.3"
http = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/trigger-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ pub struct CliArgs {
pub address: SocketAddr,

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

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

Expand Down
2 changes: 1 addition & 1 deletion crates/trigger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ unsafe-aot-compilation = []

[dependencies]
anyhow = { workspace = true }
clap = { version = "3.1.18", features = ["derive", "env"] }
clap = { version = "4", features = ["derive", "env", "wrap_help"] }
ctrlc = { version = "3.2", features = ["termination"] }
futures = { workspace = true }
sanitize-filename = "0.5"
Expand Down
20 changes: 15 additions & 5 deletions crates/trigger/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::PathBuf;
use std::{future::Future, sync::Arc};

use anyhow::{Context, Result};
use clap::{Args, IntoApp, Parser};
use clap::{Args, CommandFactory, Parser};
use spin_app::App;
use spin_common::sloth;
use spin_common::ui::quoted_path;
Expand Down Expand Up @@ -38,8 +38,9 @@ pub const SPIN_WORKING_DIR: &str = "SPIN_WORKING_DIR";
/// A command that runs a TriggerExecutor.
#[derive(Parser, Debug)]
#[clap(
usage = "spin [COMMAND] [OPTIONS]",
next_help_heading = help_heading::<T, B::Factors>()
next_help_heading = help_heading::<T, B::Factors>(),
styles = help_styles(),
max_term_width = 100,
)]
pub struct FactorsTriggerCommand<T: Trigger<B::Factors>, B: RuntimeFactorsBuilder> {
/// Log directory for the stdout and stderr of components. Setting to
Expand All @@ -58,7 +59,7 @@ pub struct FactorsTriggerCommand<T: Trigger<B::Factors>, B: RuntimeFactorsBuilde
long = "disable-cache",
env = DISABLE_WASMTIME_CACHE,
conflicts_with = WASMTIME_CACHE_FILE,
takes_value = false,
num_args = 0,
)]
pub disable_cache: bool,

Expand All @@ -79,7 +80,7 @@ pub struct FactorsTriggerCommand<T: Trigger<B::Factors>, B: RuntimeFactorsBuilde
#[clap(
name = FOLLOW_LOG_OPT,
long = "follow",
multiple_occurrences = true,
num_args = 1,
)]
pub follow_components: Vec<String>,

Expand Down Expand Up @@ -122,6 +123,15 @@ pub struct FactorsTriggerCommand<T: Trigger<B::Factors>, B: RuntimeFactorsBuilde
pub launch_metadata_only: bool,
}

/// The styles of the help output.
fn help_styles() -> clap::builder::Styles {
clap::builder::Styles::styled()
.header(clap::builder::styling::AnsiColor::Yellow.on_default())
.usage(clap::builder::styling::AnsiColor::Green.on_default())
.literal(clap::builder::styling::AnsiColor::Green.on_default())
.placeholder(clap::builder::styling::AnsiColor::Green.on_default())
}

/// Configuration options that are common to all triggers.
#[derive(Debug, Default)]
pub struct FactorsConfig {
Expand Down
2 changes: 1 addition & 1 deletion examples/spin-timer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.68"
clap = { version = "3.1.15", features = ["derive", "env"] }
clap = { version = "4", features = ["derive", "env"] }
futures = "0.3.25"
serde = "1.0.188"
spin-factors = { path = "../../crates/factors" }
Expand Down
12 changes: 8 additions & 4 deletions src/bin/spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ async fn _main() -> anyhow::Result<()> {
let mut cmd = SpinApp::command();
for plugin in &plugin_help_entries {
let subcmd = clap::Command::new(plugin.display_text())
.about(plugin.about.as_str())
.about(plugin.about.as_str().to_owned())
.allow_hyphen_values(true)
.disable_help_flag(true)
.arg(
clap::Arg::new("command")
.allow_hyphen_values(true)
.multiple_values(true),
.num_args(1),
);
cmd = cmd.subcommand(subcmd);
}
Expand Down Expand Up @@ -107,7 +107,11 @@ fn version() -> &'static str {
#[derive(Parser)]
#[clap(
name = "spin",
version = version()
version = version(),
// Display help in alphabetical order instead of default WYSIWYG order.
next_display_order = None,
styles= spin_cli::commands::help_styles(),
max_term_width = 100,
)]
enum SpinApp {
#[clap(subcommand, alias = "template")]
Expand Down Expand Up @@ -148,7 +152,7 @@ enum TriggerCommands {

impl SpinApp {
/// The main entry point to Spin.
pub async fn run(self, app: clap::Command<'_>) -> Result<(), Error> {
pub async fn run(self, app: clap::Command) -> Result<(), Error> {
match self {
Self::Templates(cmd) => cmd.run().await,
Self::Up(cmd) => cmd.run().await,
Expand Down
9 changes: 9 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ pub mod templates;
pub mod up;
/// Command for rebuilding and restarting a Spin app when files change.
pub mod watch;

/// The styles of the help output.
pub fn help_styles() -> clap::builder::Styles {
clap::builder::Styles::styled()
.header(clap::builder::styling::AnsiColor::Yellow.on_default())
.usage(clap::builder::styling::AnsiColor::Green.on_default())
.literal(clap::builder::styling::AnsiColor::Green.on_default())
.placeholder(clap::builder::styling::AnsiColor::Green.on_default())
}
Loading
Loading