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

settup clap with ArgRequiredElseHelp #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion bumblefoot/src/bin/bumblefoot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod cmd;
use anyhow::anyhow;
use console::style;
use std::process::exit;

Expand All @@ -24,7 +25,7 @@ fn main() {
);
}
let res = match matches.subcommand() {
None => cmd::default::run(&matches),
None => Err(anyhow!("command not found")),
Some(tup) => match tup {
("validate", subcommand_matches) => cmd::validate::run(&matches, subcommand_matches),
_ => unreachable!(),
Expand Down
12 changes: 2 additions & 10 deletions bumblefoot/src/bin/cmd/default.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use anyhow::Result as AnyResult;
use bumblefoot;
use clap::crate_version;
use clap::{Arg, ArgMatches, Command};
use clap::{AppSettings, Arg, Command};

pub fn command() -> Command<'static> {
Command::new("bumblefoot")
.version(env!("VERGEN_GIT_SEMVER"))
.version(crate_version!())
.about("A starter project for Rust")
.setting(AppSettings::ArgRequiredElseHelp)
.arg(
Arg::new("dry_run")
.short('d')
Expand Down Expand Up @@ -38,10 +37,3 @@ pub fn command() -> Command<'static> {
.takes_value(false),
)
}

pub fn run(matches: &ArgMatches) -> AnyResult<bool> {
log::info!("default cmd {:?}", matches.value_of("reporter"));
println!("going to run {}", bumblefoot::CMD);
bumblefoot::run();
Ok(true)
}
2 changes: 2 additions & 0 deletions bumblefoot/src/bin/cmd/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ pub fn command() -> Command<'static> {
}

pub fn run(_matches: &ArgMatches, _subcommand_matches: &ArgMatches) -> AnyResult<bool> {
println!("going to run {}", bumblefoot::CMD);
bumblefoot::run();
Ok(true)
}
4 changes: 2 additions & 2 deletions bumblefoot/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pub struct Definitions {
pub providers: HashMap<String, String>,
}

pub const CMD: &str = r#"hello"#;
pub const CMD: &str = r#"validate"#;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_foo() {
assert_eq!(CMD.len(), 5);
assert_eq!(CMD.len(), 8);
}
}