Skip to content

Commit

Permalink
command: remove Command.pos_args() and key_args()
Browse files Browse the repository at this point in the history
  • Loading branch information
erikgrinaker committed May 28, 2024
1 parent ae78f9e commit 92ca419
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
39 changes: 0 additions & 39 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 92ca419

Please sign in to comment.