diff --git a/src/app/app.rs b/src/app/app.rs index dd02aa50..f922ae1c 100644 --- a/src/app/app.rs +++ b/src/app/app.rs @@ -1330,6 +1330,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ } } } + assert!(args.len() > 0, "ArgGroup '{}' doesn't contain any args", group); args.dedup(); args.iter().map(ToOwned::to_owned).collect() } @@ -1362,6 +1363,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ } } } + assert!(args.len() > 0, "ArgGroup '{}' doesn't contain any args", group); args.dedup(); args.iter().map(|s| *s).collect() } diff --git a/src/args/group.rs b/src/args/group.rs index ecc00ec4..262f7cdd 100644 --- a/src/args/group.rs +++ b/src/args/group.rs @@ -143,6 +143,7 @@ impl<'n, 'ar> ArgGroup<'n, 'ar> { pub fn add(mut self, n: &'ar str) -> Self { + assert!(self.name != n, "ArgGroup '{}' can not have same name as arg inside it", self.name); self.args.push(n); self } diff --git a/src/tests.rs b/src/tests.rs index cbfda4a3..f8c6105f 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,6 +1,6 @@ use std::collections::HashSet; -use super::{App, Arg, SubCommand}; +use super::{App, Arg, ArgGroup, SubCommand}; use std::vec::Vec; arg_enum!{ @@ -909,3 +909,35 @@ fn create_multiple_subcommands() { .arg(Arg::with_name("other").long("other")) .get_matches(); } + +#[test] +#[should_panic] +fn empty_group() { + let _ = App::new("empty_group") + .arg(Arg::from_usage("-f, --flag 'some flag'")) + .arg_group(ArgGroup::with_name("vers") + .required(true)) + .get_matches(); +} + +#[test] +#[should_panic] +fn empty_group_2() { + let _ = App::new("empty_group") + .arg(Arg::from_usage("-f, --flag 'some flag'")) + .arg_group(ArgGroup::with_name("vers") + .required(true) + .add_all(&["ver", "major"])) + .get_matches(); +} + +#[test] +#[should_panic] +fn errous_group() { + let _ = App::new("errous_group") + .arg(Arg::from_usage("-f, --flag 'some flag'")) + .arg_group(ArgGroup::with_name("vers") + .add("vers") + .required(true)) + .get_matches(); +} \ No newline at end of file