Add ArgGroup for output options

This commit is contained in:
Matthias Beyer 2016-03-06 18:52:01 +01:00
parent 6cdc5093c4
commit b5f97a83c9
2 changed files with 11 additions and 10 deletions

View file

@ -122,15 +122,7 @@ fn list(id: &str, rt: &Runtime) {
let sepp_out = scmd.is_present("sep");
let mut comm_out = scmd.is_present("commasep");
let flags = vec![json_out, line_out, comm_out, sepp_out];
if flags.iter().filter(|x| **x).count() > 1 {
// More than one flag passed
info!("Cannot do more than one thing");
exit(1);
}
if !flags.iter().any(|v| *v) {
if !vec![json_out, line_out, comm_out, sepp_out].iter().any(|v| *v) {
// None of the flags passed, go to default
comm_out = true;
}

View file

@ -1,4 +1,4 @@
use clap::{Arg, App, SubCommand};
use clap::{Arg, App, ArgGroup, SubCommand};
pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
app.arg(Arg::with_name("id")
@ -59,6 +59,15 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.takes_value(true)
.required(false)
.help("Seperated by string"))
.group(ArgGroup::with_name("list-group")
.args(&[
"json",
"linewise",
"commasep",
"sep",
])
.required(true))
)
}