mirror of
https://github.com/gay-pizza/jaarg.git
synced 2025-12-19 07:20:18 +00:00
Compare commits
6 Commits
parse_borr
...
0.2.x
| Author | SHA1 | Date | |
|---|---|---|---|
| 75fc27bc58 | |||
| 8d9e8aea89 | |||
| 20f5a0bf10 | |||
| 7165bb9841 | |||
| 8f6f1827ce | |||
| 33af658e93 |
@@ -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]
|
||||||
|
|||||||
@@ -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`.
|
||||||
|
|||||||
@@ -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
1
jaarg/LICENSE.Apache-2.0
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE.Apache-2.0
|
||||||
1
jaarg/LICENSE.MIT
Symbolic link
1
jaarg/LICENSE.MIT
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../LICENSE.MIT
|
||||||
1
jaarg/README.md
Symbolic link
1
jaarg/README.md
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../README.md
|
||||||
@@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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]
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ impl<ID: 'static> Opts<ID> {
|
|||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod opts_tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user