-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathmain.rs
More file actions
291 lines (282 loc) · 10.3 KB
/
Copy pathmain.rs
File metadata and controls
291 lines (282 loc) · 10.3 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
use std::{env::current_dir, path::PathBuf};
use clap::{CommandFactory, Parser, Subcommand};
use color_eyre::{
Result,
config::HookBuilder,
eyre::{ContextCompat, WrapErr},
};
use repository::{Repository, inspect_version::check_for_update};
use aliveness::aliveness;
use boosterize::boosterize;
use cargo::{build, cargo, check, clippy, install, nextest, run, test};
use completions::completions;
use game_branch::game_branch;
use gammaray::gammaray;
use hulk::hulk;
use hydra_bench::hydra_bench;
use location::location;
use log::logs;
use ping::ping;
use player_number::player_number;
use post_game::post_game;
use power_off::power_off;
use pre_game::pre_game;
use reboot::reboot;
use sdk::sdk;
use shell::shell;
use tensorrt_compile::tensorrt_compile;
use tracing::warn;
use upload::upload;
use wifi::wifi;
mod aliveness;
mod boosterize;
mod cargo;
mod completions;
mod deploy_config;
mod format;
mod game_branch;
mod gammaray;
mod git;
mod hulk;
mod hydra_bench;
mod location;
mod log;
mod ping;
mod player_number;
mod post_game;
mod power_off;
mod pre_game;
mod progress_indicator;
mod reboot;
mod sdk;
mod shell;
mod tensorrt_compile;
mod upload;
mod wifi;
#[derive(Parser)]
#[clap(version, name = "pepsi")]
struct Arguments {
/// Alternative repository root
#[arg(long, visible_alias = "lagerstättenwurzel")]
repository_root: Option<PathBuf>,
#[command(subcommand)]
command: Command,
#[arg(long, visible_alias = "gesprächig")]
verbose: bool,
}
#[derive(Subcommand)]
enum Command {
/// Boosterize Robots (enable booster services)
#[command(visible_alias = "boost")]
Boosterize(boosterize::Arguments),
/// Get aliveness information from Robots
#[command(visible_alias = "lebt")]
Aliveness(aliveness::Arguments),
/// Compile a local package and all of its dependencies
#[command(visible_alias = "bau")]
Build(cargo::Arguments<build::Arguments>),
/// Check a local package and all of its dependencies for errors
#[command(visible_alias = "prüf")]
Check(cargo::Arguments<check::Arguments>),
/// Check a package to catch common mistakes
#[command(visible_alias = "klammer")]
Clippy(cargo::Arguments<clippy::Arguments>),
/// Generate shell completion files
#[command(visible_alias = "vervollständigung")]
Completions(completions::Arguments),
/// Format all rust and toml files
#[command(visible_alias = "fmt")]
Format(format::Arguments),
/// Create a game branch from the deploy.toml in the repository root
#[command(visible_alias = "spielzweig")]
Gamebranch(game_branch::Arguments),
/// Flash a HULKs-OS image to Robots
#[command(visible_alias = "gammastrahl")]
Gammaray(gammaray::Arguments),
/// Run Hydra neural-network latency benchmarks on a robot
HydraBench(hydra_bench::Arguments),
/// Control the HULK service
Hulk(hulk::Arguments),
/// Install a Rust binary
Install(cargo::Arguments<install::Arguments>),
/// Set the parameter location
#[command(subcommand, visible_alias = "ort")]
Location(location::Arguments),
/// Interact with logs on Robots
#[command(
subcommand,
visible_alias = "logs",
visible_alias = "klotz",
visible_alias = "tagebuch",
visible_alias = "baumstamm"
)]
Log(log::Arguments),
/// Run cargo nextest
#[command(visible_alias = "nächstprüf")]
Nextest(cargo::Arguments<nextest::Arguments>),
/// Change player numbers of Robots in local parameters
#[command(visible_alias = "spielerzahl")]
Playernumber(player_number::Arguments),
/// Ping Robots
#[command(visible_alias = "stups")]
Ping(ping::Arguments),
/// Disable Robots after a game (download logs, unset WiFi network, ...)
#[command(visible_alias = "nachspiel")]
Postgame(post_game::Arguments),
/// Power Robots off
#[command(visible_alias = "shutdown", visible_alias = "fahr-runter")]
Poweroff(power_off::Arguments),
/// Get Robots ready for a game (set player numbers, upload, set WiFi network, ...)
#[command(visible_alias = "vorspiel")]
Pregame(pre_game::Arguments),
/// Reboot Robots
#[command(visible_alias = "neu-stiefeln")]
Reboot(reboot::Arguments),
/// Run a binary or example of the local package
#[command(visible_alias = "lauf")]
Run(cargo::Arguments<run::Arguments>),
/// Manage the Robot SDK
#[command(subcommand, visible_alias = "sek")]
Sdk(sdk::Arguments),
/// Open a command line shell to a Robot
///
/// Example:
/// pepsi shell 20w
/// pepsi shell 42 btop
/// pepsi shell 38 39 whoami
#[command(verbatim_doc_comment, visible_alias = "muschel")]
Shell(shell::Arguments),
/// Execute all unit and integration tests
#[command()]
TensorRTCompile(tensorrt_compile::Arguments),
#[command(visible_alias = "prüf")]
Test(cargo::Arguments<test::Arguments>),
/// Upload the code to Robots
#[command(visible_alias = "hochlad")]
Upload(upload::Arguments),
/// Control WiFi on Robots
#[command(
subcommand,
name = "wifi",
visible_alias = "wlan",
visible_alias = "wireless",
visible_alias = "drahtlos"
)]
WiFi(wifi::Arguments),
}
#[tokio::main]
async fn main() -> Result<()> {
let arguments = Arguments::parse();
let level = if arguments.verbose {
tracing::Level::TRACE
} else {
tracing::Level::WARN
};
tracing_subscriber::fmt()
.without_time()
.with_max_level(level)
.init();
HookBuilder::new().display_env_section(false).install()?;
let repository = arguments
.repository_root
.map(Repository::new)
.map(Ok)
.unwrap_or_else(|| {
let current_directory = current_dir().wrap_err("failed to get current directory")?;
Repository::find_root(current_directory).wrap_err("failed to find repository root")
});
if let Ok(repository) = &repository
&& let Err(error) = check_for_update(
env!("CARGO_PKG_VERSION"),
repository.root.join("tools/pepsi/Cargo.toml"),
"pepsi",
)
{
warn!("{error:#?}");
}
match arguments.command {
Command::Aliveness(arguments) => aliveness(arguments, repository)
.await
.wrap_err("failed to execute aliveness command")?,
Command::Boosterize(arguments) => boosterize(arguments)
.await
.wrap_err("failed to execute boosterize command")?,
Command::Build(arguments) => cargo(arguments, &repository?, &[] as &[&str])
.await
.wrap_err("failed to execute build command")?,
Command::Check(arguments) => cargo(arguments, &repository?, &[] as &[&str])
.await
.wrap_err("failed to execute check command")?,
Command::Clippy(arguments) => cargo(arguments, &repository?, &[] as &[&str])
.await
.wrap_err("failed to execute clippy command")?,
Command::Completions(arguments) => completions(arguments, Arguments::command())
.await
.wrap_err("failed to execute completion command")?,
Command::Format(arguments) => format::format(arguments, &repository?)
.await
.wrap_err("failed to execute format command")?,
Command::Gamebranch(arguments) => game_branch(arguments, &repository?)
.await
.wrap_err("failed to execute gamebranch command")?,
Command::Gammaray(arguments) => gammaray(arguments, &repository?)
.await
.wrap_err("failed to execute gammaray command")?,
Command::HydraBench(arguments) => hydra_bench(arguments, &repository?)
.await
.wrap_err("failed to execute hydra-bench command")?,
Command::Hulk(arguments) => hulk(arguments)
.await
.wrap_err("failed to execute hulk command")?,
Command::Install(arguments) => cargo(arguments, &repository?, &[] as &[&str])
.await
.wrap_err("failed to execute install command")?,
Command::Location(arguments) => location(arguments, &repository?)
.await
.wrap_err("failed to execute location command")?,
Command::Log(arguments) => logs(arguments)
.await
.wrap_err("failed to execute logs command")?,
Command::Nextest(arguments) => cargo(arguments, &repository?, &[] as &[&str])
.await
.wrap_err("failed to execute nextest command")?,
Command::Ping(arguments) => ping(arguments).await,
Command::Playernumber(arguments) => player_number(arguments, &repository?)
.await
.wrap_err("failed to execute player_number command")?,
Command::Postgame(arguments) => post_game(arguments, &repository?)
.await
.wrap_err("failed to execute post_game command")?,
Command::Poweroff(arguments) => power_off(arguments, &repository?)
.await
.wrap_err("failed to execute power_off command")?,
Command::Pregame(arguments) => pre_game(arguments, &repository?)
.await
.wrap_err("failed to execute pre_game command")?,
Command::Reboot(arguments) => reboot(arguments)
.await
.wrap_err("failed to execute reboot command")?,
Command::Run(arguments) => cargo(arguments, &repository?, &[] as &[&str])
.await
.wrap_err("failed to execute run command")?,
Command::Sdk(arguments) => sdk(arguments, &repository?)
.await
.wrap_err("failed to execute sdk command")?,
Command::Shell(arguments) => shell(arguments)
.await
.wrap_err("failed to execute shell command")?,
Command::TensorRTCompile(arguments) => tensorrt_compile(arguments, &repository?)
.await
.wrap_err("failed to execute TensorRT compile command")?,
Command::Test(arguments) => cargo(arguments, &repository?, &[] as &[&str])
.await
.wrap_err("failed to execute test command")?,
Command::Upload(arguments) => upload(arguments, &repository?)
.await
.wrap_err("failed to execute upload command")?,
Command::WiFi(arguments) => wifi(arguments)
.await
.wrap_err("failed to execute wifi command")?,
}
Ok(())
}