1
+ use clap:: { arg, Parser } ;
1
2
use clap_config_file:: ClapConfigFile ;
2
3
3
4
/// This struct demonstrates usage of the ClapConfigFile derive with various attributes.
@@ -6,7 +7,8 @@ use clap_config_file::ClapConfigFile;
6
7
/// - `#[config_only]`: Field only comes from config file (or raw config data).
7
8
/// - `#[cli_only]`: Field only comes from CLI.
8
9
/// - `#[multi_value_behavior]`: Controls how `Vec` fields merge between config and CLI.
9
- #[ derive( ClapConfigFile , Debug ) ]
10
+ #[ derive( ClapConfigFile , Parser , Debug ) ]
11
+ #[ clap( trailing_var_arg = true ) ]
10
12
struct AdvancedConfig {
11
13
/// Example of a field that can come from both CLI and config, with CLI taking precedence.
12
14
///
@@ -48,6 +50,10 @@ struct AdvancedConfig {
48
50
#[ config_arg( name = "overwrite-list" ) ]
49
51
#[ multi_value_behavior( Overwrite ) ]
50
52
pub overwrite_list : Vec < String > ,
53
+
54
+ /// Any additional commands or arguments
55
+ #[ clap( last = true ) ]
56
+ pub commands : Vec < String > ,
51
57
}
52
58
53
59
fn main ( ) {
@@ -58,8 +64,11 @@ fn main() {
58
64
println ! ( "Final merged config:\n {:#?}" , config) ;
59
65
60
66
// Example usage:
61
- // $ cargo run --example advanced -- --port 3001 --overwrite-list CLI_item
67
+ // $ cargo run --example advanced -- --port 3001 --overwrite-list CLI_item additional_command
62
68
//
63
69
// That overrides the port and the overwrite_list. If advanced-config.yaml
64
70
// has `database_url` etc., that remains unless overridden or suppressed.
71
+ if !config. commands . is_empty ( ) {
72
+ println ! ( "\n Received commands: {:?}" , config. commands) ;
73
+ }
65
74
}
0 commit comments