-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlib.rs
73 lines (63 loc) · 2.29 KB
/
lib.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
// SPDX-License-Identifier: GPL-2.0-or-later
mod commands;
mod util;
use std::ffi::OsStr;
use anyhow::{bail, Result};
use clap::Parser;
use util::crun;
// Adapted from https://github.com/containers/youki/blob/main/crates/youki/src/main.rs
#[derive(Parser, Debug)]
#[clap(no_binary_name = true)]
struct Args {
#[clap(flatten)]
global: liboci_cli::GlobalOpts,
#[clap(subcommand)]
command: Command,
}
// Adapted from https://github.com/containers/youki/blob/main/crates/youki/src/main.rs
#[derive(Parser, Debug)]
enum Command {
#[clap(flatten)]
Standard(Box<liboci_cli::StandardCmd>),
#[clap(flatten)]
Common(Box<liboci_cli::CommonCmd>),
}
pub fn main(args: impl IntoIterator<Item = impl AsRef<OsStr>>) -> Result<()> {
let raw_args = args
.into_iter()
.map(|a| a.as_ref().to_os_string())
.collect::<Vec<_>>();
let parsed_args = Args::parse_from(&raw_args);
match parsed_args.command {
Command::Standard(cmd) => {
match *cmd {
liboci_cli::StandardCmd::Create(args) => commands::create::create(&args, &raw_args),
liboci_cli::StandardCmd::Delete(args) => commands::delete::delete(&args, &raw_args),
liboci_cli::StandardCmd::Start(_)
| liboci_cli::StandardCmd::State(_)
| liboci_cli::StandardCmd::Kill(_) => {
// not a command we implement ourselves, pass it on to crun
crun(&raw_args)
}
}
}
Command::Common(cmd) => {
match *cmd {
liboci_cli::CommonCmd::Exec(args) => commands::exec::exec(&args, &raw_args),
liboci_cli::CommonCmd::Checkpointt(_)
| liboci_cli::CommonCmd::Events(_)
| liboci_cli::CommonCmd::Features(_)
| liboci_cli::CommonCmd::List(_)
| liboci_cli::CommonCmd::Pause(_)
| liboci_cli::CommonCmd::Ps(_)
| liboci_cli::CommonCmd::Resume(_)
| liboci_cli::CommonCmd::Run(_)
| liboci_cli::CommonCmd::Update(_)
| liboci_cli::CommonCmd::Spec(_) => {
// not a command we support
bail!("Unknown command")
}
}
}
}
}