Skip to content

Commit 4a4c09d

Browse files
committed
Subcommand parsing with clap
1 parent 1b1a208 commit 4a4c09d

5 files changed

Lines changed: 383 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 303 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7+
clap = { version = "4.5.50", features = ["derive", "wrap_help"] }

src/env.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#[derive(Debug, clap::Subcommand)]
2+
pub enum Subcommand {
3+
/// Create an environment
4+
Create(CreateArgs),
5+
/// Activate an environment
6+
Activate,
7+
/// Deactivate an environment
8+
Deactivate,
9+
/// Run an executable in an environment
10+
Run,
11+
/// ???
12+
Pack,
13+
/// ???
14+
Unpack,
15+
/// List existing environments
16+
List,
17+
/// Display information about the micromamba setup
18+
Info,
19+
}
20+
21+
#[derive(Debug, clap::Args)]
22+
pub struct CreateArgs {
23+
/// If specified, the name of the environment. If not specified, csm will
24+
/// look to robotmk-env.yaml for a "name" field to use instead. As a last
25+
/// resort, the current directory name will be used
26+
#[arg(short, long)]
27+
name: Option<String>,
28+
}
29+
30+
pub fn run(subcommand: Subcommand) {
31+
println!("{:?}", subcommand);
32+
}

src/main.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
mod env;
2+
mod robot;
3+
4+
use clap::{Parser, Subcommand};
5+
6+
#[derive(Parser, Debug)]
7+
#[command(version)]
8+
/// Checkmk synthetic monitoring command-line tool
9+
struct Cli {
10+
#[command(subcommand)]
11+
command: Command,
12+
}
13+
14+
#[derive(Debug, Subcommand)]
15+
enum Command {
16+
/// Manipulate Robotmk environments
17+
#[command(subcommand)]
18+
Env(env::Subcommand),
19+
20+
/// Manage Robotmk robots
21+
#[command(subcommand)]
22+
Robot(robot::Subcommand),
23+
}
24+
125
fn main() {
2-
println!("Hello, world!");
26+
let cli = Cli::parse();
27+
match cli.command {
28+
Command::Env(sub) => env::run(sub),
29+
Command::Robot(sub) => robot::run(sub),
30+
}
331
}

src/robot.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#[derive(Debug, clap::Subcommand)]
2+
pub enum Subcommand {
3+
/// Create a Robotmk robot
4+
New(CreateArgs),
5+
6+
/// Run a Robotmk robot
7+
Run,
8+
}
9+
10+
#[derive(Debug, clap::Args)]
11+
pub struct CreateArgs {
12+
/// Directory path at which to create the robot
13+
path: String,
14+
}
15+
16+
pub fn run(subcommand: Subcommand) {
17+
println!("{:?}", subcommand);
18+
}

0 commit comments

Comments
 (0)