diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ba4c73b..19c2c77 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,7 +34,7 @@ jobs: RUSTFLAGS: "-D warnings" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} diff --git a/.github/workflows/msrv.yaml b/.github/workflows/msrv.yaml index 1172ee8..a05224a 100644 --- a/.github/workflows/msrv.yaml +++ b/.github/workflows/msrv.yaml @@ -34,7 +34,7 @@ jobs: RUSTFLAGS: "-D warnings" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} diff --git a/CHANGELOG.md b/CHANGELOG.md index d519afb..f2e6d0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ +## [0.8.0](https://github.com/Blobfolio/argyle/releases/tag/v0.8.0) - 2024-08-08 + +### New + +* `Argue::take_trailing` + + + ## [0.7.2](https://github.com/Blobfolio/argyle/releases/tag/v0.7.2) - 2024-02-15 ### New diff --git a/CREDITS.md b/CREDITS.md index 62049fe..0357034 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -1,6 +1,6 @@ # Project Dependencies Package: argyle - Version: 0.7.2 - Generated: 2024-02-15 20:26:13 UTC + Version: 0.8.0 + Generated: 2024-08-09 06:26:25 UTC This package has no dependencies. diff --git a/Cargo.toml b/Cargo.toml index 21503fe..e234012 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "argyle" -version = "0.7.2" +version = "0.8.0" authors = ["Blobfolio, LLC. "] edition = "2021" rust-version = "1.70" diff --git a/README.md b/README.md index 31eb688..1c04d95 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Add `argyle` to your `dependencies` in `Cargo.toml`, like: ``` [dependencies] -argyle = "0.7.*" +argyle = "0.8.*" ``` diff --git a/src/argue.rs b/src/argue.rs index 43ba79a..8914fa3 100644 --- a/src/argue.rs +++ b/src/argue.rs @@ -531,6 +531,9 @@ impl Argue { /// If you merely want something to iterate over, you can alternatively /// dereference the struct to a string slice. /// + /// If you're only interested in the _trailing_ arguments, use + /// `Argue::take_trailing` instead. + /// /// ## Examples /// /// ```no_run @@ -539,6 +542,35 @@ impl Argue { /// let args: Vec> = Argue::new(0).unwrap().take(); /// ``` pub fn take(self) -> Vec> { self.args } + + #[must_use] + /// # Take Trailing Arguments. + /// + /// Split off and return the instance's (owned) trailing arguments, + /// discarding everything else. + /// + /// As with other trailing argument-related methods, make sure you query + /// expected options before calling this method, otherwise it might + /// mistake a final associated value for a trailing argument. + /// + /// Of course, that matters less here than elsewhere since you'll lose + /// access to the switches and options anyway. Haha. + /// + /// If you want _everything_, use `Argue::take` instead. + /// + /// ## Examples + /// + /// ```no_run + /// use argyle::Argue; + /// + /// let trailing: Vec> = Argue::new(0).unwrap().take_trailing(); + /// ``` + pub fn take_trailing(self) -> Vec> { + let idx = self.arg_idx(); + let Self { mut args, .. } = self; + args.drain(..idx); + args + } } /// ## Queries. @@ -1116,15 +1148,6 @@ mod tests { // Let's see what trailing args look like when there are none. assert_eq!(args.arg(0), None); - // Let's also make sure the trailing arguments work too. - let trailing: &[&[u8]] = &[b"Hello", b"World"]; - base.extend_from_slice(trailing); - args = base.iter().copied().collect(); - assert_eq!(args.arg(0), Some(&b"Hello"[..])); - assert_eq!(args.arg(1), Some(&b"World"[..])); - assert_eq!(args.arg(2), None); - assert_eq!(args.args(), trailing); - // If there are no keys, the first entry should also be the first // argument. args = [b"hello".to_vec()].into_iter().collect(); @@ -1133,6 +1156,16 @@ mod tests { // Unless we're expecting a subcommand... args.flags |= FLAG_SUBCOMMAND; assert!(args.arg(0).is_none()); + + // Let's also make sure the trailing arguments work too. + let trailing: &[&[u8]] = &[b"Hello", b"World"]; + base.extend_from_slice(trailing); + args = base.iter().copied().collect(); + assert_eq!(args.arg(0), Some(&b"Hello"[..])); + assert_eq!(args.arg(1), Some(&b"World"[..])); + assert_eq!(args.arg(2), None); + assert_eq!(args.args(), trailing); + assert_eq!(args.take_trailing(), trailing); // This should match too. } #[test]