Use clap::ArgGroup for early exit conflicts (#94)

This commit is contained in:
Casey Rodarmor 2016-11-12 13:31:54 -08:00 committed by GitHub
parent 7cfc37f647
commit 0dcdc5dc81

View File

@ -4,7 +4,7 @@ extern crate atty;
use std::{io, fs, env, process}; use std::{io, fs, env, process};
use std::collections::BTreeMap; use std::collections::BTreeMap;
use self::clap::{App, Arg, AppSettings}; use self::clap::{App, Arg, ArgGroup, AppSettings};
use super::{Slurp, RunError}; use super::{Slurp, RunError};
macro_rules! warn { macro_rules! warn {
@ -57,31 +57,19 @@ pub fn app() {
.arg(Arg::with_name("list") .arg(Arg::with_name("list")
.short("l") .short("l")
.long("list") .long("list")
.help("Lists available recipes and their arguments") .help("Lists available recipes and their arguments"))
.conflicts_with("dump")
.conflicts_with("show")
.conflicts_with("summary"))
.arg(Arg::with_name("dump") .arg(Arg::with_name("dump")
.long("dump") .long("dump")
.help("Prints entire justfile") .help("Prints entire justfile"))
.conflicts_with("show")
.conflicts_with("summary")
.conflicts_with("list"))
.arg(Arg::with_name("show") .arg(Arg::with_name("show")
.short("s") .short("s")
.long("show") .long("show")
.takes_value(true) .takes_value(true)
.value_name("recipe") .value_name("recipe")
.help("Shows information about <recipe>") .help("Shows information about <recipe>"))
.conflicts_with("dump")
.conflicts_with("summary")
.conflicts_with("list"))
.arg(Arg::with_name("summary") .arg(Arg::with_name("summary")
.long("summary") .long("summary")
.help("Lists names of available recipes") .help("Lists names of available recipes"))
.conflicts_with("dump")
.conflicts_with("show")
.conflicts_with("list"))
.arg(Arg::with_name("quiet") .arg(Arg::with_name("quiet")
.short("q") .short("q")
.long("quiet") .long("quiet")
@ -120,6 +108,8 @@ pub fn app() {
.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"))
.group(ArgGroup::with_name("early-exit")
.args(&["dump", "list", "show", "summary"]))
.get_matches(); .get_matches();
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");