Skip to content

Commit b41a957

Browse files
authored
Update clap to v4 (#471)
1 parent 385521c commit b41a957

File tree

11 files changed

+62
-58
lines changed

11 files changed

+62
-58
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe
1414
- Our website (trunkrs.dev) now only updates on new releases.
1515
- Additional attributes are now passed through script tags (fixes #429)
1616
- Updated internal http stack to axum v0.6.0.
17+
- Updated CLI argument parser to clap v0.4.
1718
### fixed
1819
- Nested WS proxies - if `backend=ws://localhost:8000/ws` is set, queries for `ws://localhost:8080/ws/entityX` will be linked with `ws://localhost:8000/ws/entityX`
1920
- Updated all dependencies in both Trunk and its examples, to fix currently open security advisories for old dependencies.

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ axum = { version = "0.6", features = ["ws"] }
2222
bytes = "1"
2323
cargo-lock = "8"
2424
cargo_metadata = "0.15"
25-
clap = { version = "3", features = ["derive", "env"] }
25+
clap = { version = "4", features = ["derive", "env"] }
2626
console = "0.15"
2727
directories = "4"
2828
dunce = "1"

src/cmd/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use crate::config::{ConfigOpts, ConfigOptsBuild};
88

99
/// Build the Rust WASM app and all of its assets.
1010
#[derive(Clone, Debug, Args)]
11-
#[clap(name = "build")]
11+
#[command(name = "build")]
1212
pub struct Build {
13-
#[clap(flatten)]
13+
#[command(flatten)]
1414
pub build: ConfigOptsBuild,
1515
}
1616

src/cmd/clean.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use crate::tools::cache_dir;
1111

1212
/// Clean output artifacts.
1313
#[derive(Args)]
14-
#[clap(name = "clean")]
14+
#[command(name = "clean")]
1515
pub struct Clean {
16-
#[clap(flatten)]
16+
#[command(flatten)]
1717
pub clean: ConfigOptsClean,
1818
/// Optionally clean any cached tools used by Trunk
1919
///
2020
/// These tools are cached in a platform dependent "projects" dir. Removing them will cause
2121
/// them to be downloaded by Trunk next time they are needed.
22-
#[clap(short, long)]
22+
#[arg(short, long)]
2323
pub tools: bool,
2424
}
2525

src/cmd/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use crate::config::ConfigOpts;
77

88
/// Trunk config controls.
99
#[derive(Clone, Debug, Args)]
10-
#[clap(name = "config")]
10+
#[command(name = "config")]
1111
pub struct Config {
12-
#[clap(subcommand)]
12+
#[command(subcommand)]
1313
action: ConfigSubcommands,
1414
}
1515

src/cmd/serve.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use crate::serve::ServeSystem;
99

1010
/// Build, watch & serve the Rust WASM app and all of its assets.
1111
#[derive(Args)]
12-
#[clap(name = "serve")]
12+
#[command(name = "serve")]
1313
pub struct Serve {
14-
#[clap(flatten)]
14+
#[command(flatten)]
1515
pub build: ConfigOptsBuild,
16-
#[clap(flatten)]
16+
#[command(flatten)]
1717
pub watch: ConfigOptsWatch,
18-
#[clap(flatten)]
18+
#[command(flatten)]
1919
pub serve: ConfigOptsServe,
2020
}
2121

src/cmd/watch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use crate::watch::WatchSystem;
99

1010
/// Build & watch the Rust WASM app and all of its assets.
1111
#[derive(Args)]
12-
#[clap(name = "watch")]
12+
#[command(name = "watch")]
1313
pub struct Watch {
14-
#[clap(flatten)]
14+
#[command(flatten)]
1515
pub build: ConfigOptsBuild,
16-
#[clap(flatten)]
16+
#[command(flatten)]
1717
pub watch: ConfigOptsWatch,
1818
}
1919

src/common.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Common functionality and types.
22
3+
use std::convert::Infallible;
34
use std::ffi::OsStr;
45
use std::fmt::Debug;
56
use std::fs::Metadata;
@@ -22,10 +23,10 @@ static CWD: Lazy<PathBuf> =
2223
Lazy::new(|| std::env::current_dir().expect("error getting current dir"));
2324

2425
/// Ensure the given value for `--public-url` is formatted correctly.
25-
pub fn parse_public_url(val: &str) -> String {
26+
pub fn parse_public_url(val: &str) -> Result<String, Infallible> {
2627
let prefix = if !val.starts_with('/') { "/" } else { "" };
2728
let suffix = if !val.ends_with('/') { "/" } else { "" };
28-
format!("{}{}{}", prefix, val, suffix)
29+
Ok(format!("{}{}{}", prefix, val, suffix))
2930
}
3031

3132
/// A utility function to recursively copy a directory.

src/config/models.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,31 @@ use crate::pipelines::PipelineStage;
1717
#[derive(Clone, Debug, Default, Deserialize, Args)]
1818
pub struct ConfigOptsBuild {
1919
/// The index HTML file to drive the bundling process [default: index.html]
20-
#[clap(parse(from_os_str))]
2120
pub target: Option<PathBuf>,
2221
/// Build in release mode [default: false]
23-
#[clap(long)]
22+
#[arg(long)]
2423
#[serde(default)]
2524
pub release: bool,
2625
/// The output dir for all final assets [default: dist]
27-
#[clap(short, long, parse(from_os_str))]
26+
#[arg(short, long)]
2827
pub dist: Option<PathBuf>,
2928
/// The public URL from which assets are to be served [default: /]
30-
#[clap(long, parse(from_str=parse_public_url))]
29+
#[arg(long, value_parser = parse_public_url)]
3130
pub public_url: Option<String>,
3231
/// Build without default features [default: false]
33-
#[clap(long)]
32+
#[arg(long)]
3433
#[serde(default)]
3534
pub no_default_features: bool,
3635
/// Build with all features [default: false]
37-
#[clap(long)]
36+
#[arg(long)]
3837
#[serde(default)]
3938
pub all_features: bool,
4039
/// A comma-separated list of features to activate, must not be used with all-features
4140
/// [default: ""]
42-
#[clap(long)]
41+
#[arg(long)]
4342
pub features: Option<String>,
4443
/// Whether to include hash values in the output file names [default: true]
45-
#[clap(long)]
44+
#[arg(long)]
4645
pub filehash: Option<bool>,
4746
/// Optional pattern for the app loader script [default: None]
4847
///
@@ -51,7 +50,7 @@ pub struct ConfigOptsBuild {
5150
/// to key/value pairs provided in `pattern_params`.
5251
///
5352
/// These values can only be provided via config file.
54-
#[clap(skip)]
53+
#[arg(skip)]
5554
#[serde(default)]
5655
pub pattern_script: Option<String>,
5756
/// Optional pattern for the app preload element [default: None]
@@ -61,10 +60,10 @@ pub struct ConfigOptsBuild {
6160
/// to key/value pairs provided in `pattern_params`.
6261
///
6362
/// These values can only be provided via config file.
64-
#[clap(skip)]
63+
#[arg(skip)]
6564
#[serde(default)]
6665
pub pattern_preload: Option<String>,
67-
#[clap(skip)]
66+
#[arg(skip)]
6867
#[serde(default)]
6968
/// Optional replacement parameters corresponding to the patterns provided in
7069
/// `pattern_script` and `pattern_preload`.
@@ -86,45 +85,45 @@ pub struct ConfigOptsBuild {
8685
#[derive(Clone, Debug, Default, Deserialize, Args)]
8786
pub struct ConfigOptsWatch {
8887
/// Watch specific file(s) or folder(s) [default: build target parent folder]
89-
#[clap(short, long, parse(from_os_str), value_name = "path")]
88+
#[arg(short, long, value_name = "path")]
9089
pub watch: Option<Vec<PathBuf>>,
9190
/// Paths to ignore [default: []]
92-
#[clap(short, long, parse(from_os_str), value_name = "path")]
91+
#[arg(short, long, value_name = "path")]
9392
pub ignore: Option<Vec<PathBuf>>,
9493
}
9594

9695
/// Config options for the serve system.
9796
#[derive(Clone, Debug, Default, Deserialize, Args)]
9897
pub struct ConfigOptsServe {
9998
/// The address to serve on [default: 127.0.0.1]
100-
#[clap(long)]
99+
#[arg(long)]
101100
pub address: Option<IpAddr>,
102101
/// The port to serve on [default: 8080]
103-
#[clap(long)]
102+
#[arg(long)]
104103
pub port: Option<u16>,
105104
/// Open a browser tab once the initial build is complete [default: false]
106-
#[clap(long)]
105+
#[arg(long)]
107106
#[serde(default)]
108107
pub open: bool,
109108
/// A URL to which requests will be proxied [default: None]
110-
#[clap(long = "proxy-backend")]
109+
#[arg(long = "proxy-backend")]
111110
#[serde(default, deserialize_with = "deserialize_uri")]
112111
pub proxy_backend: Option<Uri>,
113112
/// The URI on which to accept requests which are to be rewritten and proxied to backend
114113
/// [default: None]
115-
#[clap(long = "proxy-rewrite")]
114+
#[arg(long = "proxy-rewrite")]
116115
#[serde(default)]
117116
pub proxy_rewrite: Option<String>,
118117
/// Configure the proxy for handling WebSockets [default: false]
119-
#[clap(long = "proxy-ws")]
118+
#[arg(long = "proxy-ws")]
120119
#[serde(default)]
121120
pub proxy_ws: bool,
122121
/// Configure the proxy to accept insecure requests [default: false]
123-
#[clap(long = "proxy-insecure")]
122+
#[arg(long = "proxy-insecure")]
124123
#[serde(default)]
125124
pub proxy_insecure: bool,
126125
/// Disable auto-reload of the web app [default: false]
127-
#[clap(long = "no-autoreload")]
126+
#[arg(long = "no-autoreload")]
128127
#[serde(default)]
129128
pub no_autoreload: bool,
130129
}
@@ -133,10 +132,10 @@ pub struct ConfigOptsServe {
133132
#[derive(Clone, Debug, Default, Deserialize, Args)]
134133
pub struct ConfigOptsClean {
135134
/// The output dir for all final assets [default: dist]
136-
#[clap(short, long, parse(from_os_str))]
135+
#[arg(short, long)]
137136
pub dist: Option<PathBuf>,
138137
/// Optionally perform a cargo clean [default: false]
139-
#[clap(long)]
138+
#[arg(long)]
140139
#[serde(default)]
141140
pub cargo: bool,
142141
}

0 commit comments

Comments
 (0)