@@ -20,80 +20,97 @@ pub struct Build {
2020pub  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+ } 
0 commit comments