diff --git a/CHANGELOG.md b/CHANGELOG.md index 3954c0f..ffe3172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +**Breaking changes** + +* Remove `Command.pos_args()` and `key_args()`, use `consume_args()`. + **Improvements** * Add `Command.consume_args()` for convenient argument handling. diff --git a/src/command.rs b/src/command.rs index 562464d..bdbdd64 100644 --- a/src/command.rs +++ b/src/command.rs @@ -39,16 +39,6 @@ impl Command { pub fn consume_args(&self) -> ArgumentConsumer<'_> { ArgumentConsumer::new(&self.args) } - - /// Returns all key/value arguments, in their original order. - pub fn key_args(&self) -> Vec<&Argument> { - self.args.iter().filter(|a| a.key.is_some()).collect() - } - - /// Returns all positional arguments (no key), in their original order. - pub fn pos_args(&self) -> Vec<&Argument> { - self.args.iter().filter(|a| a.key.is_none()).collect() - } } /// A command argument. @@ -200,35 +190,6 @@ mod tests { }}; } - /// Tests Command.pos_args() and key_args(). - #[test] - fn command_pos_key_args() { - // Empty argument list. - let cmd = cmd!("cmd"); - assert!(cmd.pos_args().is_empty()); - assert!(cmd.key_args().is_empty()); - - // Only key/value arguments. - let cmd = cmd!("cmd key=value foo=bar"); - assert!(cmd.pos_args().is_empty()); - assert_eq!(cmd.key_args(), vec![&cmd.args[0], &cmd.args[1]]); - - // Only positional arguments. - let cmd = cmd!("cmd foo value"); - assert_eq!(cmd.pos_args(), vec![&cmd.args[0], &cmd.args[1]]); - assert!(cmd.key_args().is_empty()); - - // Mixed arguments. - let cmd = cmd!("cmd foo foo=bar value key=value"); - assert_eq!(cmd.pos_args(), vec![&cmd.args[0], &cmd.args[2]]); - assert_eq!(cmd.key_args(), vec![&cmd.args[1], &cmd.args[3]]); - - // Duplicate key/value arguments. - let cmd = cmd!("cmd key=1 key=2 key=3"); - assert!(cmd.pos_args().is_empty()); - assert_eq!(cmd.key_args(), vec![&cmd.args[0], &cmd.args[1], &cmd.args[2]]); - } - /// Tests Argument.name(). #[test] fn argument_name() {