Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: print help when no subcommand is provided #104

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pub enum CliArgumentError {
#[error("invalid log format: {0}")]
InvalidLogFormat(String),
#[error("missing subcommand")]
MissingSubcommand,
}

#[derive(thiserror::Error, Debug)]
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use {
/// bulwark-cli launches and interacts with the Bulwark service.
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[clap(arg_required_else_help = true)]
struct Cli {
/// Log levels: error, warn, info, debug, trace
///
Expand Down Expand Up @@ -152,8 +153,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// You can check for the existence of subcommands, and if found use their
// matches just as you would the top level cmd
match &cli.command {
Some(Command::ExtProcessor { config }) => {
match &cli.command.ok_or(CliArgumentError::MissingSubcommand)? {
Command::ExtProcessor { config } => {
let mut service_tasks: JoinSet<std::result::Result<(), ServiceError>> = JoinSet::new();

let config_root = bulwark_config::toml::load_config(config)?;
Expand Down Expand Up @@ -274,7 +275,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
}
Some(Command::Build { path, output }) => {
Command::Build { path, output } => {
let current_dir = std::env::current_dir()?;
let path = path.clone().unwrap_or(current_dir.clone());
let wasm_filename = crate::build::wasm_filename(&path)?;
Expand All @@ -287,7 +288,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
crate::build::build_plugin(&path, output)?;
}
None => todo!(),
}

Ok(())
Expand Down
Loading