1
1
//! Bottlerocket Settings Extension CLI proto1 definition.
2
2
#![ allow( missing_docs) ]
3
- use clap :: { Args , Subcommand } ;
3
+ use argh :: FromArgs ;
4
4
5
- #[ derive( Args , Debug ) ]
5
+ /// Use Settings Extension CLI protocol proto1.
6
+ #[ derive( FromArgs , Debug ) ]
7
+ #[ argh( subcommand, name = "proto1" ) ]
6
8
pub struct Protocol1 {
7
- #[ command( subcommand) ]
9
+ /// the command to invoke against the settings extension
10
+ #[ argh( subcommand) ]
8
11
pub command : Proto1Command ,
9
12
}
10
13
11
- #[ derive( Subcommand , Debug ) ]
14
+ /// The command to invoke against the settings extension.
15
+ #[ derive( FromArgs , Debug ) ]
16
+ #[ argh( subcommand) ]
12
17
pub enum Proto1Command {
13
18
/// Modify values owned by this setting
14
19
Set ( SetCommand ) ,
@@ -22,92 +27,109 @@ pub enum Proto1Command {
22
27
/// Migrate this setting from one given version to another
23
28
Migrate ( MigrateCommand ) ,
24
29
30
+ /// Migrate this setting from one given version to all other known versions
31
+ FloodMigrate ( FloodMigrateCommand ) ,
32
+
25
33
/// Execute a helper. Typically this is used to render config templates
26
34
Helper ( TemplateHelperCommand ) ,
27
35
}
28
36
29
37
impl Proto1Command { }
30
38
31
- #[ derive( Args , Debug ) ]
39
+ /// Validates that a new setting value can be persisted to the Bottlerocket datastore.
40
+ #[ derive( FromArgs , Debug ) ]
41
+ #[ argh( subcommand, name = "set" ) ]
32
42
pub struct SetCommand {
33
- /// The version of the setting which should be used
34
- #[ arg ( long ) ]
43
+ /// the version of the setting which should be used
44
+ #[ argh ( option ) ]
35
45
pub setting_version : String ,
36
46
37
- /// The requested value to be set for the incoming setting
38
- #[ arg ( long , value_parser = parse_json ) ]
47
+ /// the requested value to be set for the incoming setting
48
+ #[ argh ( option ) ]
39
49
pub value : serde_json:: Value ,
40
50
41
- /// The current value of this settings tree
42
- #[ arg ( long , value_parser = parse_json ) ]
51
+ /// the current value of this settings tree
52
+ #[ argh ( option ) ]
43
53
pub current_value : Option < serde_json:: Value > ,
44
54
}
45
55
46
- #[ derive( Args , Debug ) ]
56
+ /// Dynamically generates a value for this setting given, possibly from other settings.
57
+ #[ derive( FromArgs , Debug ) ]
58
+ #[ argh( subcommand, name = "generate" ) ]
47
59
pub struct GenerateCommand {
48
- /// The version of the setting which should be used
49
- #[ arg ( long ) ]
60
+ /// the version of the setting which should be used
61
+ #[ argh ( option ) ]
50
62
pub setting_version : String ,
51
63
52
- /// A json value containing any partially generated data for this setting
53
- #[ arg ( long , value_parser = parse_json ) ]
64
+ /// a json value containing any partially generated data for this setting
65
+ #[ argh ( option ) ]
54
66
pub existing_partial : Option < serde_json:: Value > ,
55
67
56
- /// A json value containing any requested settings partials needed to generate this one
57
- #[ arg ( long , value_parser = parse_json ) ]
68
+ /// a json value containing any requested settings partials needed to generate this one
69
+ #[ argh ( option ) ]
58
70
pub required_settings : Option < serde_json:: Value > ,
59
71
}
60
72
61
- #[ derive( Args , Debug ) ]
73
+ /// Validates an incoming setting, possibly cross-validated with other settings.
74
+ #[ derive( FromArgs , Debug ) ]
75
+ #[ argh( subcommand, name = "validate" ) ]
62
76
pub struct ValidateCommand {
63
- /// The version of the setting which should be used
64
- #[ arg ( long ) ]
77
+ /// the version of the setting which should be used
78
+ #[ argh ( option ) ]
65
79
pub setting_version : String ,
66
80
67
- /// A json value containing any partially generated data for this setting
68
- #[ arg ( long , value_parser = parse_json ) ]
81
+ /// a json value containing any partially generated data for this setting
82
+ #[ argh ( option ) ]
69
83
pub value : serde_json:: Value ,
70
84
71
- /// A json value containing any requested settings partials needed to generate this one
72
- #[ arg ( long , value_parser = parse_json ) ]
85
+ /// a json value containing any requested settings partials needed to generate this one
86
+ #[ argh ( option ) ]
73
87
pub required_settings : Option < serde_json:: Value > ,
74
88
}
75
89
76
- #[ derive( Args , Debug ) ]
90
+ /// Migrates a setting value from one version to another.
91
+ #[ derive( FromArgs , Debug ) ]
92
+ #[ argh( subcommand, name = "migrate" ) ]
77
93
pub struct MigrateCommand {
78
- /// A json value containing the current value of the setting
79
- #[ arg ( long , value_parser = parse_json ) ]
94
+ /// a json value containing the current value of the setting
95
+ #[ argh ( option ) ]
80
96
pub value : serde_json:: Value ,
81
97
82
- /// The version of the settings data being migrated
83
- #[ arg ( long ) ]
98
+ /// the version of the settings data being migrated
99
+ #[ argh ( option ) ]
84
100
pub from_version : String ,
85
101
86
- /// The desired resulting version for the settings data
87
- #[ arg( long, group = "migration-type" ) ]
88
- pub target_version : Option < String > ,
102
+ /// the desired resulting version for the settings data
103
+ #[ argh( option) ]
104
+ pub target_version : String ,
105
+ }
106
+
107
+ /// Migrates a setting value from one version to all other known versions.
108
+ #[ derive( FromArgs , Debug ) ]
109
+ #[ argh( subcommand, name = "flood-migrate" ) ]
110
+ pub struct FloodMigrateCommand {
111
+ /// a json value containing the current value of the setting
112
+ #[ argh( option) ]
113
+ pub value : serde_json:: Value ,
89
114
90
- /// Triggers a batch migration to all known setting versions
91
- #[ arg ( long , group = "migration-type" ) ]
92
- pub flood : bool ,
115
+ /// the version of the settings data being migrated
116
+ #[ argh ( option ) ]
117
+ pub from_version : String ,
93
118
}
94
119
95
- #[ derive( Args , Debug ) ]
120
+ /// Executes a template helper to assist in rendering values to a configuration file.
121
+ #[ derive( FromArgs , Debug ) ]
122
+ #[ argh( subcommand, name = "helper" ) ]
96
123
pub struct TemplateHelperCommand {
97
- /// The version of the setting which should be used
98
- #[ arg ( long ) ]
124
+ /// the version of the setting which should be used
125
+ #[ argh ( option ) ]
99
126
pub setting_version : String ,
100
127
101
- /// The name of the helper to call
102
- #[ arg ( long ) ]
128
+ /// the name of the helper to call
129
+ #[ argh ( option ) ]
103
130
pub helper_name : String ,
104
131
105
- /// The arguments for the given helper
106
- #[ arg ( long , value_parser = parse_json ) ]
132
+ /// the arguments for the given helper
133
+ #[ argh ( option ) ]
107
134
pub arg : Vec < serde_json:: Value > ,
108
135
}
109
-
110
- /// Helper for `clap` to parse JSON values.
111
- fn parse_json ( arg : & str ) -> Result < serde_json:: Value , serde_json:: Error > {
112
- serde_json:: from_str ( arg)
113
- }
0 commit comments