Use clap's conflicts_with and requires (#68)

Seems better than writing it by hand.
This commit is contained in:
Casey Rodarmor 2016-11-11 20:47:17 -08:00 committed by GitHub
parent 0f9fb418a0
commit 98990fe2ab
2 changed files with 16 additions and 19 deletions

View File

@ -76,10 +76,12 @@ pub fn app() {
.arg(Arg::with_name("quiet") .arg(Arg::with_name("quiet")
.short("q") .short("q")
.long("quiet") .long("quiet")
.help("Suppress all output")) .help("Suppress all output")
.conflicts_with("dry-run"))
.arg(Arg::with_name("dry-run") .arg(Arg::with_name("dry-run")
.long("dry-run") .long("dry-run")
.help("Print recipe text without executing")) .help("Print recipe text without executing")
.conflicts_with("quiet"))
.arg(Arg::with_name("evaluate") .arg(Arg::with_name("evaluate")
.long("evaluate") .long("evaluate")
.help("Print evaluated variables")) .help("Print evaluated variables"))
@ -99,28 +101,18 @@ pub fn app() {
.arg(Arg::with_name("working-directory") .arg(Arg::with_name("working-directory")
.long("working-directory") .long("working-directory")
.takes_value(true) .takes_value(true)
.help("Use <working-directory> as working directory. --justfile must also be set")) .help("Use <working-directory> as working directory. --justfile must also be set")
.requires("justfile"))
.arg(Arg::with_name("justfile") .arg(Arg::with_name("justfile")
.long("justfile") .long("justfile")
.takes_value(true) .takes_value(true)
.help("Use <justfile> as justfile. --working-directory must also be set")) .help("Use <justfile> as justfile. --working-directory must also be set")
.requires("working-directory"))
.arg(Arg::with_name("arguments") .arg(Arg::with_name("arguments")
.multiple(true) .multiple(true)
.help("The recipe(s) to run, defaults to the first recipe in the justfile")) .help("The recipe(s) to run, defaults to the first recipe in the justfile"))
.get_matches(); .get_matches();
// it is not obvious to me what we should do if only one of --justfile and
// --working-directory are passed. refuse to run in that case to avoid
// suprises.
if matches.is_present("justfile") ^ matches.is_present("working-directory") {
die!("--justfile and --working-directory may only be used together");
}
// --dry-run and --quiet don't make sense together
if matches.is_present("dry-run") && matches.is_present("quiet") {
die!("--dry-run and --quiet may not be used together");
}
let use_color_argument = matches.value_of("color").expect("--color had no value"); let use_color_argument = matches.value_of("color").expect("--color had no value");
let use_color = UseColor::from_argument(use_color_argument); let use_color = UseColor::from_argument(use_color_argument);

View File

@ -809,10 +809,15 @@ default:
fn quiet_flag_or_dry_run_flag() { fn quiet_flag_or_dry_run_flag() {
integration_test( integration_test(
&["--quiet", "--dry-run"], &["--quiet", "--dry-run"],
r#""#,
255,
"", "",
"--dry-run and --quiet may not be used together\n", 1,
"",
"error: The argument '--dry-run' cannot be used with '--quiet'
USAGE:
just --quiet --color <color>
For more information try --help\n",
); );
} }