forked from PowerShell/DSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargs.rs
234 lines (226 loc) · 10 KB
/
args.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use clap::{Parser, Subcommand, ValueEnum};
use clap_complete::Shell;
use dsc_lib::dscresources::command_resource::TraceLevel;
use dsc_lib::progress::ProgressFormat;
use rust_i18n::t;
use serde::Deserialize;
#[derive(Debug, Clone, PartialEq, Eq, ValueEnum)]
pub enum OutputFormat {
Json,
PrettyJson,
Yaml,
}
#[derive(Debug, Clone, PartialEq, Eq, ValueEnum, Deserialize)]
pub enum TraceFormat {
Default,
Plaintext,
Json,
#[clap(hide = true)]
PassThrough,
}
#[derive(Debug, Parser)]
#[clap(name = "dsc", version = env!("CARGO_PKG_VERSION"), about = t!("args.about").to_string(), long_about = None)]
pub struct Args {
/// The subcommand to run
#[clap(subcommand)]
pub subcommand: SubCommand,
#[clap(short = 'l', long, help = t!("args.traceLevel").to_string(), value_enum)]
pub trace_level: Option<TraceLevel>,
#[clap(short = 't', long, help = t!("args.traceFormat").to_string(), value_enum)]
pub trace_format: Option<TraceFormat>,
#[clap(short = 'p', long, help = t!("args.progressFormat").to_string(), value_enum)]
pub progress_format: Option<ProgressFormat>,
}
#[derive(Debug, PartialEq, Eq, Subcommand)]
pub enum SubCommand {
#[clap(name = "completer", about = t!("args.completer").to_string())]
Completer {
/// The shell to generate a completion script for
shell: Shell,
},
#[clap(name = "config", about = t!("args.configAbout").to_string())]
Config {
#[clap(subcommand)]
subcommand: ConfigSubCommand,
#[clap(short, long, help = t!("args.parameters").to_string(), conflicts_with = "parameters_file")]
parameters: Option<String>,
#[clap(short = 'f', long, help = t!("args.parametersFile").to_string(), conflicts_with = "parameters")]
parameters_file: Option<String>,
#[clap(short = 'r', long, help = t!("args.systemRoot").to_string())]
system_root: Option<String>,
// Used to inform when DSC is used as a group resource to modify it's output
#[clap(long, hide = true)]
as_group: bool,
// Used to inform when DSC is used as a include group resource
#[clap(long, hide = true)]
as_include: bool,
},
#[clap(name = "resource", about = t!("args.resourceAbout").to_string())]
Resource {
#[clap(subcommand)]
subcommand: ResourceSubCommand,
},
#[clap(name = "schema", about = t!("args.schemaAbout").to_string())]
Schema {
#[clap(name = "type", short, long, help = t!("args.schemaType").to_string(), value_enum)]
dsc_type: DscType,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string(), value_enum)]
output_format: Option<OutputFormat>,
},
}
#[derive(Debug, PartialEq, Eq, Subcommand)]
pub enum ConfigSubCommand {
#[clap(name = "get", about = t!("args.getAbout").to_string())]
Get {
#[clap(short = 'i', long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string(), value_enum)]
output_format: Option<OutputFormat>,
},
#[clap(name = "set", about = t!("args.setAbout").to_string())]
Set {
#[clap(short = 'i', long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
#[clap(short = 'w', long, help = t!("args.whatIf").to_string())]
what_if: bool,
},
#[clap(name = "test", about = t!("args.testAbout").to_string())]
Test {
#[clap(short = 'i', long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
// Used by Assertion resource to return `test` result as a `get` result
#[clap(long, hide = true)]
as_get: bool,
// Used by Assertion resource to return `test` result as a configuration `test` result
#[clap(long, hide = true)]
as_config: bool,
},
#[clap(name = "validate", about = t!("args.validateAbout").to_string(), hide = true)]
Validate {
#[clap(short = 'i', long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
},
#[clap(name = "export", about = t!("args.exportAbout").to_string())]
Export {
#[clap(short = 'i', long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
},
#[clap(name = "resolve", about = t!("args.resolveAbout").to_string(), hide = true)]
Resolve {
#[clap(short = 'i', long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
}
}
#[derive(Debug, PartialEq, Eq, Subcommand)]
pub enum ResourceSubCommand {
#[clap(name = "list", about = t!("args.listAbout").to_string())]
List {
/// Optional filter to apply to the list of resources
resource_name: Option<String>,
/// Optional adapter filter to apply to the list of resources
#[clap(short = 'a', long = "adapter", help = t!("args.adapter").to_string())]
adapter_name: Option<String>,
#[clap(short, long, help = t!("args.description").to_string())]
description: Option<String>,
#[clap(short, long, help = t!("args.tags").to_string())]
tags: Option<Vec<String>>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
},
#[clap(name = "get", about = t!("args.resourceGet").to_string(), arg_required_else_help = true)]
Get {
#[clap(short, long, help = t!("args.getAll").to_string())]
all: bool,
#[clap(short, long, help = t!("args.resource").to_string())]
resource: String,
#[clap(short, long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
},
#[clap(name = "set", about = "Invoke the set operation to a resource", arg_required_else_help = true)]
Set {
#[clap(short, long, help = t!("args.resource").to_string())]
resource: String,
#[clap(short, long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
},
#[clap(name = "test", about = "Invoke the test operation to a resource", arg_required_else_help = true)]
Test {
#[clap(short, long, help = t!("args.resource").to_string())]
resource: String,
#[clap(short, long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
},
#[clap(name = "delete", about = "Invoke the delete operation to a resource", arg_required_else_help = true)]
Delete {
#[clap(short, long, help = t!("args.resource").to_string())]
resource: String,
#[clap(short, long, help = t!("args.input").to_string(), conflicts_with = "file")]
input: Option<String>,
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
file: Option<String>,
},
#[clap(name = "schema", about = "Get the JSON schema for a resource", arg_required_else_help = true)]
Schema {
#[clap(short, long, help = t!("args.resource").to_string())]
resource: String,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
},
#[clap(name = "export", about = "Retrieve all resource instances", arg_required_else_help = true)]
Export {
#[clap(short, long, help = t!("args.resource").to_string())]
resource: String,
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
output_format: Option<OutputFormat>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum DscType {
GetResult,
SetResult,
TestResult,
ResolveResult,
DscResource,
ResourceManifest,
Include,
Configuration,
ConfigurationGetResult,
ConfigurationSetResult,
ConfigurationTestResult,
}