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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
// Copyright Pit Kleyersburg <pitkley@googlemail.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified or distributed
// except according to those terms.
use clap::{
crate_authors, crate_description, crate_name, crate_version, App, AppSettings, Arg, SubCommand,
};
pub fn cli() -> App<'static, 'static> {
let working_directory = Arg::with_name("working-directory")
.help("Directory used as context for starting the applications")
.long_help(
"Directory used as context for starting the applications. This overrides any specified \
working-directory in the projects configuration.",
)
.short("d")
.long("working-directory")
.takes_value(true)
.value_name("PATH")
.required(false);
let workspace = Arg::with_name("workspace")
.help("Workspace to apply the layout to")
.long_help(
"Workspace to apply the layout to. This overrides the specified workspace in the \
projects configuration.",
)
.short("w")
.long("workspace")
.takes_value(true)
.value_name("WORKSPACE")
.required(false);
App::new(crate_name!())
.version(crate_version!())
.author(crate_authors!())
.about(crate_description!())
.global_settings(&[
AppSettings::ColoredHelp,
AppSettings::GlobalVersion,
AppSettings::InferSubcommands,
AppSettings::VersionlessSubcommands,
])
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
SubCommand::with_name("copy")
.about("Copy an existing project to a new project")
.arg(
Arg::with_name("EXISTING")
.help("Name of the existing project")
.required(true),
)
.arg(
Arg::with_name("NEW")
.help("Name of the new, destination project")
.required(true),
)
.arg(
Arg::with_name("no-edit")
.help("Don't open the new project for editing after copying")
.long("no-edit")
.required(false),
)
.arg(
Arg::with_name("no-verify")
.help(
"Don't verify the contents of the new project after the editor closes",
)
.long("no-verify")
.required(false)
.conflicts_with("no-edit"),
),
)
.subcommand(
SubCommand::with_name("delete")
.alias("remove")
.about("Delete existing projects")
.arg(
Arg::with_name("NAME")
.help("Names of the projects to delete")
.multiple(true)
.required(true),
),
)
.subcommand(
SubCommand::with_name("edit")
.alias("open")
.about("Open an existing project in your editor")
.arg(
Arg::with_name("NAME")
.help("Name of the project to edit")
.required(true),
)
.arg(
Arg::with_name("no-verify")
.help(
"Don't verify the contents of the new project after the editor closes",
)
.long("no-verify")
.required(false),
),
)
.subcommand(
SubCommand::with_name("info")
.about("Show information for the specified project")
.arg(
Arg::with_name("NAME")
.help("Name of the project to show information for")
.required(true),
),
)
.subcommand(
SubCommand::with_name("list")
.about("List all projects")
.arg(
Arg::with_name("quiet")
.help("List one project per line, no other output")
.short("q")
.long("quiet")
.takes_value(false)
.required(false),
),
)
.subcommand(
SubCommand::with_name("local")
.about("Run a project from a local TOML-file")
.arg(
Arg::with_name("file")
.help("File to load the project from")
.short("f")
.long("file")
.value_name("FILE")
.default_value("i3nator.toml"),
)
.arg(working_directory.clone())
.arg(workspace.clone()),
)
.subcommand(
SubCommand::with_name("new")
.about("Create a new project and open it in your editor")
.arg(
Arg::with_name("NAME")
.help("Name of the project to create")
.required(true),
)
.arg(
Arg::with_name("no-edit")
.help("Don't open the new project for editing")
.long("no-edit")
.required(false),
)
.arg(
Arg::with_name("no-verify")
.help(
"Don't verify the contents of the new project after the editor closes",
)
.long("no-verify")
.required(false)
.conflicts_with("no-edit"),
),
)
.subcommand(
SubCommand::with_name("rename")
.about("Rename a project")
.arg(
Arg::with_name("CURRENT")
.help("Name of the existing project to rename")
.required(true),
)
.arg(
Arg::with_name("NEW")
.help("New name for the existing project")
.required(true),
)
.arg(
Arg::with_name("edit")
.help("Open the renamed project for editing")
.long("edit")
.required(false),
)
.arg(
Arg::with_name("no-verify")
.help(
"Don't verify the contents of the new project after the editor closes",
)
.long("no-verify")
.required(false)
.requires("edit"),
),
)
.subcommand(
SubCommand::with_name("start")
.alias("run")
.about("Start a project according to it's configuration")
.arg(
Arg::with_name("NAME")
.help("Name of the project to start")
.required(true),
)
.arg(working_directory)
.arg(workspace),
)
.subcommand(
SubCommand::with_name("verify")
.about("Verify the configuration of the existing projects")
.arg(
Arg::with_name("NAME")
.help("Names of the projects to verify")
.long_help(
"Name of the projects to verify. If not specified, all projects will \
be checked.",
)
.multiple(true)
.required(false),
),
)
.subcommand(cli_layout())
}
pub fn cli_layout() -> App<'static, 'static> {
SubCommand::with_name("layout")
.about("Manage layouts which can used in projects")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
SubCommand::with_name("copy")
.about("Copy an existing layout to a new layout")
.arg(
Arg::with_name("EXISTING")
.help("Name of the existing layout")
.required(true),
)
.arg(
Arg::with_name("NEW")
.help("Name of the new, destination layout")
.required(true),
)
.arg(
Arg::with_name("no-edit")
.help("Don't open the new layout for editing after copying")
.long("no-edit")
.required(false),
),
)
.subcommand(
SubCommand::with_name("delete")
.alias("remove")
.about("Delete existing layouts")
.arg(
Arg::with_name("NAME")
.help("Names of the layouts to delete")
.multiple(true)
.required(true),
),
)
.subcommand(
SubCommand::with_name("edit")
.alias("open")
.about("Open an existing layout in your editor")
.arg(
Arg::with_name("NAME")
.help("Name of the layout to edit")
.required(true),
),
)
.subcommand(
SubCommand::with_name("info")
.about("Show information for the specified layout")
.arg(
Arg::with_name("NAME")
.help("Name of the layout to show information for")
.required(true),
),
)
.subcommand(
SubCommand::with_name("list").about("List all layouts").arg(
Arg::with_name("quiet")
.help("List one layout per line, no other output")
.short("q")
.long("quiet")
.takes_value(false)
.required(false),
),
)
.subcommand(
SubCommand::with_name("new")
.about("Create a new layout and open it in your editor")
.arg(
Arg::with_name("NAME")
.help("Name of the layout to create")
.required(true),
)
.arg(
Arg::with_name("no-edit")
.help("Don't open the new layout for editing")
.long("no-edit")
.required(false),
)
.arg(
Arg::with_name("template")
.help(
"Prepopulate the layout from the given path. Use '-' to read from \
stdin.",
)
.short("t")
.long("template")
.takes_value(true)
.value_name("TEMPLATE")
.required(false),
),
)
.subcommand(
SubCommand::with_name("rename")
.about("Rename a layout")
.arg(
Arg::with_name("CURRENT")
.help("Name of the existing layout to rename")
.required(true),
)
.arg(
Arg::with_name("NEW")
.help("New name for the existing layout")
.required(true),
)
.arg(
Arg::with_name("edit")
.help("Open the renamed layout for editing")
.long("edit")
.required(false),
),
)
}