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
//! `msb start` command — start/resume an existing stopped sandbox.
use clap::Args;
use microsandbox::sandbox::Sandbox;
use crate::ui;
use super::common;
//--------------------------------------------------------------------------------------------------
// Types
//--------------------------------------------------------------------------------------------------
/// Start a stopped sandbox.
#[derive(Debug, Args)]
pub struct StartArgs {
/// Sandbox(es) to start. Required unless `--label` is given.
#[arg(required_unless_present = "label")]
pub names: Vec<String>,
/// Start every sandbox carrying this label (`KEY=VALUE`). Repeatable;
/// AND-matched. Unioned with any explicitly named sandboxes.
#[arg(long)]
pub label: Vec<String>,
/// Suppress progress output.
#[arg(short, long)]
pub quiet: bool,
}
//--------------------------------------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------------------------------------
/// Execute the `msb start` command.
pub async fn run(args: StartArgs) -> anyhow::Result<()> {
let names = common::resolve_bulk_targets(&args.names, &args.label, args.quiet).await?;
let mut failed = false;
for name in &names {
let spinner = if args.quiet {
ui::Spinner::quiet()
} else {
ui::Spinner::start("Starting", name)
};
match Sandbox::start_detached(name).await {
Ok(sandbox) => {
sandbox.detach().await;
spinner.finish_success("Started");
}
Err(e) => {
spinner.finish_clear();
if !args.quiet {
ui::error(&format!("{e}"));
}
failed = true;
}
}
}
if failed {
std::process::exit(1);
}
Ok(())
}