6 Commits

Author SHA1 Message Date
75fc27bc58 Release 0.2.2 2025-11-26 15:30:43 +11:00
8d9e8aea89 Cargo stinky aaaa 2025-11-26 15:26:07 +11:00
20f5a0bf10 Backport positional argument handler fix. 2025-11-26 15:12:49 +11:00
7165bb9841 Rename test modules for previously included files.
(cherry picked from commit 75e2bde5fb)
2025-11-26 15:03:55 +11:00
8f6f1827ce Add simple argparse test for values
(cherry picked from commit 14028ed2c8)
2025-11-26 15:03:28 +11:00
33af658e93 Add homepage
(cherry picked from commit 23b6402db6)
2025-11-26 15:00:54 +11:00
9 changed files with 58 additions and 5 deletions

View File

@@ -4,11 +4,12 @@ members = ["jaarg-nostd"]
resolver = "3" resolver = "3"
[workspace.package] [workspace.package]
version = "0.2.1" version = "0.2.2"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
edition = "2021" edition = "2021"
description = "It can parse your arguments you should use it it's called jaarg" description = "It can parse your arguments you should use it it's called jaarg"
repository = "https://github.com/gay-pizza/jaarg" repository = "https://github.com/gay-pizza/jaarg"
homepage = "https://gay.pizza/"
authors = ["a dinosaur", "Gay Pizza Specifications"] authors = ["a dinosaur", "Gay Pizza Specifications"]
[profile.release] [profile.release]

View File

@@ -57,8 +57,10 @@ println!("{file:?} -> {out:?} (number: {number:?})",
### Changelog ### ### Changelog ###
main: v0.2.2:
* Fixed coerced `ArgumentError` not being rewritten for positional arguments.
* Moved top level includes to `pub use`. * Moved top level includes to `pub use`.
* Hopefully work around licence & read me texts not being included in crate.
v0.2.1: v0.2.1:
* Fixed licence field in `Cargo.toml`. * Fixed licence field in `Cargo.toml`.

View File

@@ -4,6 +4,7 @@ version.workspace = true
license.workspace = true license.workspace = true
edition.workspace = true edition.workspace = true
description.workspace = true description.workspace = true
homepage.workspace = true
repository.workspace = true repository.workspace = true
authors.workspace = true authors.workspace = true

1
jaarg/LICENSE.Apache-2.0 Symbolic link
View File

@@ -0,0 +1 @@
../LICENSE.Apache-2.0

1
jaarg/LICENSE.MIT Symbolic link
View File

@@ -0,0 +1 @@
../LICENSE.MIT

1
jaarg/README.md Symbolic link
View File

@@ -0,0 +1 @@
../README.md

View File

@@ -232,7 +232,7 @@ impl<ID: 'static> Opts<ID> {
// Find the next positional argument // Find the next positional argument
for (i, option) in self.options[state.positional_index..].iter().enumerate() { for (i, option) in self.options[state.positional_index..].iter().enumerate() {
if matches!(option.r#type, OptType::Positional) { if matches!(option.r#type, OptType::Positional) {
handler(program_name, &option.id, option, option.first_name(), token)?; call_handler(option, option.first_name(), token)?;
state.positional_index += i + 1; state.positional_index += i + 1;
return Ok(ParseControl::Continue); return Ok(ParseControl::Continue);
} }
@@ -242,3 +242,49 @@ impl<ID: 'static> Opts<ID> {
} }
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse() {
extern crate alloc;
use alloc::string::String;
enum ArgID { One, Two, Three, Four, Five }
const OPTIONS: Opts<ArgID> = Opts::new(&[
Opt::positional(ArgID::One, "one"),
Opt::flag(ArgID::Two, &["--two"]),
Opt::value(ArgID::Three, &["--three"], "value"),
Opt::value(ArgID::Four, &["--four"], "value"),
Opt::value(ArgID::Five, &["--five"], "value"),
]);
const ARGUMENTS: &[&str] = &["one", "--two", "--three=three", "--five=", "--four", "four"];
//TODO: currently needs alloc to deal with arguments not being able to escape handler
let mut one: Option<String> = None;
let mut two = false;
let mut three: Option<String> = None;
let mut four: Option<String> = None;
let mut five: Option<String> = None;
assert!(matches!(OPTIONS.parse("", ARGUMENTS.iter(), |_program_name, id, _opt, _name, arg| {
match id {
ArgID::One => { one = Some(arg.into()); }
ArgID::Two => { two = true; }
ArgID::Three => { three = Some(arg.into()); }
ArgID::Four => { four = Some(arg.into()); }
ArgID::Five => { five = Some(arg.into()); }
}
Ok(ParseControl::Continue)
}, |_, error| {
panic!("unreachable: {error:?}");
}), ParseResult::ContinueSuccess));
assert_eq!(one, Some("one".into()));
assert!(two);
assert_eq!(three, Some("three".into()));
assert_eq!(four, Some("four".into()));
assert_eq!(five, Some("".into()));
}
}

View File

@@ -241,7 +241,7 @@ impl core::ops::BitOr for OptFlag {
} }
#[cfg(test)] #[cfg(test)]
mod opt_tests { mod tests {
use super::*; use super::*;
#[test] #[test]

View File

@@ -79,7 +79,7 @@ impl<ID: 'static> Opts<ID> {
#[cfg(test)] #[cfg(test)]
mod opts_tests { mod tests {
use super::*; use super::*;
#[test] #[test]