-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathargs.rs
More file actions
337 lines (271 loc) 路 7.76 KB
/
Copy pathargs.rs
File metadata and controls
337 lines (271 loc) 路 7.76 KB
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
335
336
337
#![allow(clippy::module_name_repetitions)]
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
/// Path to the vfs to use.
#[arg(long, default_value = None)]
pub vfs: Option<PathBuf>,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
#[clap(hide = true)]
Postinstall,
/// Build the project and install it locally (into VFS).
Build(BuildArgs),
/// Export an installed app as a zip archive.
Export(ExportArgs),
/// Install locally an app from a zip archive.
#[clap(alias("install"))]
Import(ImportArgs),
/// Bootstrap a new app.
#[clap(alias("create"), alias("bootstrap"))]
New(NewArgs),
/// Launch firefly-emulator.
Emulator(EmulatorArgs),
/// Run tests.
#[clap(alias("tests"), alias("pytest"))]
Test(TestArgs),
/// List all badges (aka achievements) defined in the given app.
#[clap(alias("badge"), alias("achievements"), alias("achievement"))]
Badges(BadgesArgs),
/// List all boards (aka scoreboards or leaderboards) defined in the given app.
#[clap(
alias("board"),
alias("scoreboard"),
alias("leaderboard"),
alias("scoreboards"),
alias("leaderboards"),
alias("scores")
)]
Boards(BoardsArgs),
/// Show the full path to the virtual filesystem.
Vfs,
/// Control a running device or emulator.
Runtime(RuntimeArgs),
/// Inspect contents of the ROM: files, metadata, wasm binary.
Inspect(InspectArgs),
/// Run interactive session.
Repl(ReplArgs),
/// Manage screenshots.
#[command(subcommand)]
#[clap(alias("shot"), alias("screenshot"), alias("screenshots"))]
Shots(ShotsCommands),
/// Set, get, and generate device name.
#[command(subcommand)]
Name(NameCommands),
/// Interact with catalog.fireflyzero.com.
#[command(subcommand)]
Catalog(CatalogCommands),
}
#[derive(Subcommand, Debug)]
pub enum NameCommands {
/// Show the current device name.
#[clap(alias("show"), alias("echo"))]
Get,
/// Set a new device name.
#[clap(alias("change"))]
Set(NameSetArgs),
/// Set a new device name.
#[clap(alias("gen"), alias("new"))]
Generate,
}
#[derive(Subcommand, Debug)]
pub enum CatalogCommands {
/// List all games available in the catalog.
#[clap(alias("ls"), alias("apps"))]
List(CatalogListArgs),
/// Show info about an app or author.
#[clap(alias("info"), alias("app"), alias("author"))]
Show(CatalogShowArgs),
}
#[derive(Subcommand, Debug)]
pub enum ShotsCommands {
/// Download screenshot from vfs.
#[clap(
alias("get"),
alias("fetch"),
alias("cp"),
alias("copy"),
alias("import")
)]
Download(ShotsDownloadArgs),
}
#[derive(Debug, Parser)]
pub struct NameSetArgs {
pub name: String,
}
#[derive(Debug, Parser)]
pub struct TestArgs {}
#[derive(Debug, Parser, Default)]
pub struct BuildArgs {
/// Path to the project root.
#[arg(default_value = ".")]
pub root: PathBuf,
/// Path to the directory where to store roms
#[arg(short, long, default_value = None)]
pub roms: Option<PathBuf>,
/// Path to the firefly config.
#[arg(short, long, default_value = None)]
pub config: Option<PathBuf>,
/// Don't optimize the binary.
#[arg(long, default_value_t = false)]
pub no_opt: bool,
/// Don't strip debug info and custom sections.
#[arg(long, default_value_t = false)]
pub no_strip: bool,
/// Don't show a random tip.
#[arg(long, default_value_t = false)]
pub no_tip: bool,
}
#[derive(Debug, Parser)]
pub struct ExportArgs {
/// Path to the project root.
#[arg(long, default_value = ".")]
pub root: PathBuf,
/// Full app ID.
#[arg(long, default_value = None)]
pub id: Option<String>,
/// Path to the archive.
#[arg(short, long, default_value = None)]
pub output: Option<PathBuf>,
}
#[derive(Debug, Parser)]
pub struct BadgesArgs {
/// Full app ID.
pub id: String,
/// Show hidden badges.
#[arg(long, default_value_t = false)]
pub hidden: bool,
}
#[derive(Debug, Parser)]
pub struct BoardsArgs {
/// Full app ID.
pub id: String,
}
#[derive(Debug, Parser)]
pub struct ImportArgs {
/// The ROM to install.
///
/// The ROM can be one of:
///
/// 1. Local path to a zip file (for example, `sys.launcher.zip`)
///
/// 2. URL of a zip file (for example, `https://example.com/sys.launcher.zip`)
///
/// 3. App ID in the catalog (for example, `sys.launcher`).
///
/// 4. The word "launcher" to install the latest version of the default launcher.
#[arg()]
pub path: String,
}
#[derive(Debug, Parser)]
pub struct NewArgs {
/// The directory name to create, the new project root and name.
#[arg()]
pub name: String,
/// The programming language to use for the project.
#[arg(long, alias("language"))]
pub lang: String,
}
#[derive(Debug, Parser)]
pub struct EmulatorArgs {
/// Download the latest emulator release.
#[arg(long, default_value_t = false)]
pub update: bool,
/// Arguments to pass into the emulator.
pub args: Vec<String>,
}
#[derive(Debug, Parser)]
pub struct ShotsDownloadArgs {
/// Screenshot(s) to download: author ID, app ID, or screenshot path.
pub source: String,
/// Directory where to save the screenshots.
#[arg(short, long, default_value = None)]
pub output: Option<PathBuf>,
}
#[derive(Debug, Parser)]
pub struct InspectArgs {
/// ID of the ROM to inspect.
///
/// If not specified, the ID of the current project is used.
#[arg(default_value = None)]
pub id: Option<String>,
/// Path to the project root.
#[arg(long, default_value = ".")]
pub root: PathBuf,
}
#[derive(Debug, Parser)]
pub struct CheatArgs {
/// The command to pass into the app.
///
/// Either an integer or a command listed in firefly.toml.
#[arg()]
pub command: String,
/// The value to pass into the app.
///
/// Either an integer, boolean, or a character.
#[arg()]
pub value: String,
/// Path to the project root.
#[arg(default_value = ".")]
pub root: PathBuf,
}
#[derive(Debug, Parser)]
pub struct RuntimeArgs {
/// Path to serial port to connect to a running device.
#[arg(long, default_value = None)]
pub port: Option<String>,
#[arg(long, default_value_t = 115_200)]
pub baud_rate: u32,
#[command(subcommand)]
pub command: RuntimeCommands,
}
#[derive(Debug, Parser)]
pub enum RuntimeCommands {
/// Send a cheat code.
Cheat(CheatArgs),
/// Show runtime stats.
Monitor,
/// Show live runtime logs.
Logs,
/// Take a screenshot.
#[clap(alias("shot"), alias("snap"), alias("photo"))]
Screenshot,
/// Launch the given app.
#[clap(alias("start"), alias("execute"), alias("open"))]
Launch(LaunchArgs),
/// Restart the running app.
#[clap(alias("reload"))]
Restart,
/// Close the running app and go back to launcher.
#[clap(alias("close"), alias("stop"), alias("terminate"), alias("launcher"))]
Exit,
/// Fetch and print the ID of the running app.
Id,
}
#[derive(Debug, Parser)]
pub struct LaunchArgs {
/// The app ID to launch. For example, "lux.snek".
#[arg()]
pub id: String,
}
#[derive(Debug, Parser)]
pub struct ReplArgs {
/// Path to the project root.
#[arg(default_value = ".")]
pub root: PathBuf,
}
#[derive(Debug, Parser)]
pub struct CatalogListArgs {
// TODO(@orsinium): support JSON
}
#[derive(Debug, Parser)]
pub struct CatalogShowArgs {
/// The app/author ID to get info for. For example, "lux.snek".
#[arg()]
pub id: String,
}