@@ -20,80 +20,97 @@ pub struct Build {
20
20
pub target : Option < PathBuf > ,
21
21
22
22
/// Build in release mode
23
- #[ arg( long) ]
23
+ #[ arg( long, env = "TRUNK_BUILD_RELEASE" ) ]
24
+ #[ arg( default_missing_value="true" , num_args=0 ..=1 ) ]
24
25
pub release : Option < bool > ,
25
26
26
27
/// The output dir for all final assets
27
- #[ arg( short, long) ]
28
+ #[ arg( short, long, env = "TRUNK_BUILD_DIST" ) ]
28
29
pub dist : Option < PathBuf > ,
29
30
30
31
/// 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 ) ]
32
34
pub offline : Option < bool > ,
33
35
34
36
/// 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 ) ]
36
39
pub frozen : Option < bool > ,
37
40
38
41
/// 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 ) ]
40
44
pub locked : Option < bool > ,
41
45
42
46
/// The public URL from which assets are to be served
43
- #[ arg( long) ]
47
+ #[ arg( long, env = "TRUNK_BUILD_PUBLIC_URL" ) ]
44
48
pub public_url : Option < BaseUrl > ,
45
49
46
50
/// 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 ) ]
48
53
pub public_url_no_trailing_slash_fix : Option < bool > ,
49
54
50
55
/// 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 ) ]
52
58
pub no_default_features : Option < bool > ,
53
59
54
60
/// 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 ) ]
56
63
pub all_features : Option < bool > ,
57
64
58
65
/// 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
+ ) ]
60
72
pub features : Option < Vec < String > > ,
61
73
62
74
/// 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 ) ]
64
77
pub filehash : Option < bool > ,
65
78
66
79
/// 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" ) ]
68
81
pub root_certificate : Option < String > ,
69
82
70
- /// Allows request to ignore certificate validation errors.
83
+ /// Allows request to ignore certificate validation errors (danger!)
71
84
///
72
85
/// 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 ) ]
74
88
pub accept_invalid_certs : Option < bool > ,
75
89
76
90
/// Enable minification.
77
91
///
78
92
/// 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 ) ]
80
95
pub minify : Option < bool > ,
81
96
82
97
/// 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 ) ]
84
100
pub no_sri : Option < bool > ,
85
101
86
102
/// Ignore error's related to self-closing script elements, and instead issue a warning.
87
103
///
88
104
/// Since this issue can cause the HTML output to be truncated, only enable this in case you
89
105
/// 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 ) ]
91
108
pub allow_self_closing_script : Option < bool > ,
92
109
110
+ // NOTE: flattened structures come last
93
111
#[ command( flatten) ]
94
112
pub core : super :: core:: Core ,
95
113
96
- // NOTE: flattened structures come last
97
114
#[ command( flatten) ]
98
115
pub tools : Tools ,
99
116
}
@@ -177,3 +194,24 @@ impl Build {
177
194
Ok ( ( ) )
178
195
}
179
196
}
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
+ }
0 commit comments