Skip to content

Commit

Permalink
feat(snot-cli): cli autocompletions
Browse files Browse the repository at this point in the history
  • Loading branch information
gluax committed Mar 30, 2024
1 parent 029c2de commit 369bdf5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bimap = "0.6"
bincode = "1.3"
chrono = "0.4"
clap = { version = "4.5", features = ["derive"] }
clap_complete = { version = "4.5" }
colored = "2"
external-ip = "4.2.0"
futures = "0.3"
Expand Down
1 change: 1 addition & 0 deletions crates/snot-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"

anyhow.workspace = true
clap.workspace = true
clap_complete.workspace = true
reqwest = { workspace = true, features = ["blocking", "json"] }
serde_json = { workspace = true }
url.workspace = true
2 changes: 1 addition & 1 deletion crates/snot-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::Parser;
#[derive(Debug, Parser)]
#[clap(name = "snot-cli", author = "MONADIC.US")]
pub struct Cli {
// /// The subcommand to run.
/// The subcommand to run.
#[clap(subcommand)]
pub subcommand: crate::commands::Commands,
}
Expand Down
19 changes: 11 additions & 8 deletions crates/snot-cli/src/commands/env.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::path::PathBuf;

use anyhow::Result;
use clap::Parser;
use clap::{Parser, ValueHint};
use serde_json::Value;

/// For interacting with snot tests.
/// For interacting with snop environments.
#[derive(Debug, Parser)]
pub struct Env {
/// The url the control plane is on.
#[clap(short, long, default_value = "http://localhost:1234")]
#[clap(short, long, default_value = "http://localhost:1234", value_hint = ValueHint::Url)]
url: String,
#[clap(subcommand)]
command: Commands,
Expand All @@ -20,18 +20,21 @@ enum Commands {
/// Prepare a (test) environment.
Prepare {
/// The test spec file.
#[clap(value_hint = ValueHint::AnyPath)]
spec: PathBuf,
},

/// Start an environment's timeline (a test).
Start { id: usize },
Start {
/// Start a specific env.
#[clap(value_hint = ValueHint::Other)]
id: usize,
},

/// Stop an environment's timeline.
Stop {
/// Stop all envs.
// #[clap(short, long)]
// all: bool,
/// Stop a specific test.
/// Stop a specific env.
#[clap(value_hint = ValueHint::Other)]
id: usize,
},
}
Expand Down
16 changes: 15 additions & 1 deletion crates/snot-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
use anyhow::Result;
use clap::Parser;
use clap::{CommandFactory, Parser};

use crate::cli::Cli;

mod env;

#[derive(Debug, Parser)]
pub enum Commands {
/// Generate shell completions.
Autocomplete {
/// Which shell you want to generate completions for.
shell: clap_complete::Shell,
},
Env(env::Env),
}

impl Commands {
pub fn run(self) -> Result<()> {
match self {
Commands::Autocomplete { shell } => {
let mut cmd = Cli::command();
let cmd_name = cmd.get_name().to_string();

clap_complete::generate(shell, &mut cmd, cmd_name, &mut std::io::stdout());
Ok(())
}
Commands::Env(test) => test.run(),
}
}
Expand Down

0 comments on commit 369bdf5

Please sign in to comment.