Skip to content

Commit 265599c

Browse files
committed
chore: fixup some regressions from the config refactoring
* Add env-var variants for the build command arguments * For boolean flags, allow non-value variant * Other minor cleanups Closes #803
1 parent c3012a7 commit 265599c

File tree

8 files changed

+71
-22
lines changed

8 files changed

+71
-22
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Just a few simple items to keep in mind as you hack.
77

88
- Pull request early and often. This helps to let others know what you are working on. **Please use GitHub's Draft PR mechanism** if your PR is not yet ready for review.
99
- Use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/), a changelog will automatically be created from such commits
10+
- When making changes to the configuration, be sure to regenate the schema. This can be done by running:
11+
12+
```shell
13+
cargo run -- config generate-schema schemas/config.json
14+
```
1015

1116
## linting
1217
We are using clippy & rustfmt. Clippy is SO GREAT! Rustfmt ... has a lot more growing to do; however, we are using it for uniformity.

Trunk.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ignore = []
3535

3636
[serve]
3737
# The address to serve on.
38-
address = "127.0.0.1"
38+
addresses = ["127.0.0.1"]
3939
# The port to serve on.
4040
port = 8080
4141
# Open a browser tab once the initial build is complete.

schemas/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
]
352352
},
353353
"insecure": {
354-
"description": "Configure the proxy to accept insecure certificates.",
354+
"description": "Configure the proxy to accept insecure certificates (danger!).",
355355
"default": false,
356356
"type": "boolean"
357357
},

src/cmd/build.rs

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,80 +20,97 @@ pub struct Build {
2020
pub target: Option<PathBuf>,
2121

2222
/// Build in release mode
23-
#[arg(long)]
23+
#[arg(long, env = "TRUNK_BUILD_RELEASE")]
24+
#[arg(default_missing_value="true", num_args=0..=1)]
2425
pub release: Option<bool>,
2526

2627
/// The output dir for all final assets
27-
#[arg(short, long)]
28+
#[arg(short, long, env = "TRUNK_BUILD_DIST")]
2829
pub dist: Option<PathBuf>,
2930

3031
/// Run without accessing the network
31-
#[arg(long)]
32+
#[arg(long, env = "TRUNK_BUILD_OFFLINE")]
33+
#[arg(default_missing_value="true", num_args=0..=1)]
3234
pub offline: Option<bool>,
3335

3436
/// Require Cargo.lock and cache are up to date
35-
#[arg(long)]
37+
#[arg(long, env = "TRUNK_BUILD_FROZEN")]
38+
#[arg(default_missing_value="true", num_args=0..=1)]
3639
pub frozen: Option<bool>,
3740

3841
/// Require Cargo.lock is up to date
39-
#[arg(long)]
42+
#[arg(long, env = "TRUNK_BUILD_LOCKED")]
43+
#[arg(default_missing_value="true", num_args=0..=1)]
4044
pub locked: Option<bool>,
4145

4246
/// The public URL from which assets are to be served
43-
#[arg(long)]
47+
#[arg(long, env = "TRUNK_BUILD_PUBLIC_URL")]
4448
pub public_url: Option<BaseUrl>,
4549

4650
/// Don't add a trailing slash to the public URL if it is missing
47-
#[arg(long)]
51+
#[arg(long, env = "TRUNK_BUILD_PUBLIC_URL_NO_TRAILING_SLASH")]
52+
#[arg(default_missing_value="true", num_args=0..=1)]
4853
pub public_url_no_trailing_slash_fix: Option<bool>,
4954

5055
/// Build without default features
51-
#[arg(long)]
56+
#[arg(long, env = "TRUNK_BUILD_NO_DEFAULT_FEATURES")]
57+
#[arg(default_missing_value="true", num_args=0..=1)]
5258
pub no_default_features: Option<bool>,
5359

5460
/// Build with all features
55-
#[arg(long)]
61+
#[arg(long, env = "TRUNK_BUILD_ALL_FEATURES")]
62+
#[arg(default_missing_value="true", num_args=0..=1)]
5663
pub all_features: Option<bool>,
5764

5865
/// A comma-separated list of features to activate, must not be used with all-features
59-
#[arg(long, conflicts_with = "all_features", value_delimiter = ',')]
66+
#[arg(
67+
long,
68+
conflicts_with = "all_features",
69+
value_delimiter = ',',
70+
env = "TRUNK_BUILD_FEATURES"
71+
)]
6072
pub features: Option<Vec<String>>,
6173

6274
/// Whether to include hash values in the output file names
63-
#[arg(long)]
75+
#[arg(long, env = "TRUNK_BUILD_FILEHASH")]
76+
#[arg(default_missing_value="true", num_args=0..=1)]
6477
pub filehash: Option<bool>,
6578

6679
/// When desired, set a custom root certificate chain (same format as Cargo's config.toml http.cainfo)
67-
#[arg(long)]
80+
#[arg(long, env = "TRUNK_BUILD_ROOT_CERTIFICATE")]
6881
pub root_certificate: Option<String>,
6982

70-
/// Allows request to ignore certificate validation errors.
83+
/// Allows request to ignore certificate validation errors (danger!)
7184
///
7285
/// Can be useful when behind a corporate proxy.
73-
#[arg(long)]
86+
#[arg(long, env = "TRUNK_BUILD_ACCEPT_INVALID_CERTS")]
87+
#[arg(default_missing_value="true", num_args=0..=1)]
7488
pub accept_invalid_certs: Option<bool>,
7589

7690
/// Enable minification.
7791
///
7892
/// This overrides the value from the configuration file.
79-
#[arg(short = 'M', long)]
93+
#[arg(short = 'M', long, env = "TRUNK_BUILD_MINIFY")]
94+
#[arg(default_missing_value="true", num_args=0..=1)]
8095
pub minify: Option<bool>,
8196

8297
/// Allows disabling sub-resource integrity (SRI)
83-
#[arg(long)]
98+
#[arg(long, env = "TRUNK_BUILD_NO_SRI")]
99+
#[arg(default_missing_value="true", num_args=0..=1)]
84100
pub no_sri: Option<bool>,
85101

86102
/// Ignore error's related to self-closing script elements, and instead issue a warning.
87103
///
88104
/// Since this issue can cause the HTML output to be truncated, only enable this in case you
89105
/// are sure it is caused due to a false positive.
90-
#[arg(long)]
106+
#[arg(long, env = "TRUNK_BUILD_ALLOW_SELF_CLOSING_SCRIPT")]
107+
#[arg(default_missing_value="true", num_args=0..=1)]
91108
pub allow_self_closing_script: Option<bool>,
92109

110+
// NOTE: flattened structures come last
93111
#[command(flatten)]
94112
pub core: super::core::Core,
95113

96-
// NOTE: flattened structures come last
97114
#[command(flatten)]
98115
pub tools: Tools,
99116
}
@@ -177,3 +194,24 @@ impl Build {
177194
Ok(())
178195
}
179196
}
197+
198+
#[cfg(test)]
199+
mod test {
200+
use crate::{Trunk, TrunkSubcommands};
201+
use clap::Parser;
202+
use rstest::rstest;
203+
204+
#[rstest]
205+
#[case(&["trunk", "build"], None)]
206+
#[case(&["trunk", "build", "--no-default-features"], Some(true))]
207+
#[case(&["trunk", "build", "--no-default-features", "true"], Some(true))]
208+
#[case(&["trunk", "build", "--no-default-features", "false"], Some(false))]
209+
fn test_bool_no_arg(#[case] input: &[&str], #[case] expected: Option<bool>) {
210+
let cli = Trunk::parse_from(input);
211+
let TrunkSubcommands::Build(build) = cli.action else {
212+
panic!("must be a build command");
213+
};
214+
215+
assert_eq!(build.no_default_features, expected);
216+
}
217+
}

src/cmd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Trunk's subcommands
2+
23
pub mod build;
34
pub mod clean;
45
pub mod config;

src/cmd/serve.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ pub struct Serve {
3030
/// Open a browser tab once the initial build is complete [default: false]
3131
#[arg(long, env = "TRUNK_SERVE_OPEN")]
3232
pub open: bool,
33-
/// Disable auto-reload of the web app [default: false]
33+
/// Disable auto-reload of the web app
3434
#[arg(long, env = "TRUNK_SERVE_NO_AUTORELOAD")]
35+
#[arg(default_missing_value="true", num_args=0..=1)]
3536
pub no_autoreload: Option<bool>,
3637
/// Disable error reporting in the browser [default: false]
3738
#[arg(long, env = "TRUNK_SERVE_NO_ERROR_REPORTING")]
39+
#[arg(default_missing_value="true", num_args=0..=1)]
3840
pub no_error_reporting: Option<bool>,
3941
/// Disable fallback to index.html for missing files [default: false]
4042
#[arg(long, env = "TRUNK_SERVE_NO_SPA")]
43+
#[arg(default_missing_value="true", num_args=0..=1)]
4144
pub no_spa: Option<bool>,
4245
/// Protocol used for the auto-reload WebSockets connection [enum: ws, wss]
4346
#[arg(long, env = "TRUNK_SERVE_WS_PROTOCOL")]
@@ -55,6 +58,7 @@ pub struct Serve {
5558
#[arg(long, env = "TRUNK_SERVE_SERVE_BASE")]
5659
pub serve_base: Option<String>,
5760

61+
// NOTE: flattened structures come last
5862
#[command(flatten)]
5963
pub proxy: ProxyArgs,
6064

src/cmd/watch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct Watch {
3333
#[arg(long, env = "TRUNK_WATCH_ENABLE_COOLDOWN")]
3434
pub enable_cooldown: bool,
3535

36+
// NOTE: flattened structures come last
3637
#[command(flatten)]
3738
pub build: super::build::Build,
3839
}

src/config/models/proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct Proxy {
1616
/// Configure the proxy for handling WebSockets.
1717
#[serde(default)]
1818
pub ws: bool,
19-
/// Configure the proxy to accept insecure certificates.
19+
/// Configure the proxy to accept insecure certificates (danger!).
2020
#[serde(default)]
2121
pub insecure: bool,
2222
/// Configure the proxy to bypass the system proxy.

0 commit comments

Comments
 (0)