diff --git a/Cargo.lock b/Cargo.lock index 569a5ad..312f59d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,7 +24,7 @@ checksum = "010e18bd3bfd1d45a7e666b236c78720df0d9a7698ebaa9c1c559961eb60a38b" [[package]] name = "tiny-cli" -version = "0.3.0" +version = "0.3.1" dependencies = [ "tiny-std", ] diff --git a/tiny-cli/Cargo.toml b/tiny-cli/Cargo.toml index f65e4e8..9fc5a3f 100644 --- a/tiny-cli/Cargo.toml +++ b/tiny-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tiny-cli" -version = "0.3.0" +version = "0.3.1" edition = "2021" license = "MPL-2.0" readme = "../Readme.md" diff --git a/tiny-cli/Changelog.md b/tiny-cli/Changelog.md index 16765f0..ed3016c 100644 --- a/tiny-cli/Changelog.md +++ b/tiny-cli/Changelog.md @@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed +## [v0.3.1] - 2024-08-26 + +### Fixed +- Correctly handles different visibilities on Arg structs + ## [v0.3.0] - 2024-08-24 ### Fixed diff --git a/tiny-cli/src/derive_struct.rs b/tiny-cli/src/derive_struct.rs index 20ad081..3d761c0 100644 --- a/tiny-cli/src/derive_struct.rs +++ b/tiny-cli/src/derive_struct.rs @@ -393,8 +393,36 @@ fn parse_annotation_group(g: &Group) -> GroupParseResult { } } +#[allow(clippy::too_many_lines)] fn parse_member>(ident: &Ident, it: &mut I) -> ParsedMember { - let field_name = ident.to_string(); + let mut field_name = ident.to_string(); + if field_name == "pub" { + match it.next() { + None => { + panic!("Expected visibility to be followed by an ident found nothing"); + } + Some(tt) => match tt { + TokenTree::Group(g) => { + let count = g.stream().into_iter().count(); + assert_eq!( + 1, count, + "Expected a single identifier after 'pub(', found {g}" + ); + field_name = + pop_ident(it, "Expected to find an ident after visibility").to_string(); + } + TokenTree::Ident(id) => { + field_name = id.to_string(); + } + TokenTree::Punct(p) => { + panic!("Found punctuation '{p}' after visibility specifier, expected an ident"); + } + TokenTree::Literal(l) => { + panic!("Found literal {l} after visibility specifier, expected an ident"); + } + }, + } + } pop_expect_punct(it, ':', "Failed to parse member, expected ':' punctuation"); let next = it .next() diff --git a/tiny-cli/src/lib.rs b/tiny-cli/src/lib.rs index 817538c..16ab8a2 100644 --- a/tiny-cli/src/lib.rs +++ b/tiny-cli/src/lib.rs @@ -29,7 +29,7 @@ fn pop_expect_punct, D: Display>( assert_eq!(p.as_char(), expect, "{err_msg}"); } else { panic!( - "[ArgParse derive] Expected punctation with {expect}, found: {punct:?}, ctx: {err_msg}" + "[ArgParse derive] Expected punctuation with {expect}, found: {punct:?}, ctx: {err_msg}" ); } } @@ -54,7 +54,7 @@ fn pop_ident, D: Display>(stream: &mut I, err_msg: if let TokenTree::Ident(ident) = ident { ident } else { - panic!("[ArgParse derive] Expected ident, found {ident:?}, ctx: {err_msg}"); + panic!("[ArgParse derive] Expected ident, found '{ident:?}', ctx: {err_msg}"); } } diff --git a/tiny-cli/tests/derive_test.rs b/tiny-cli/tests/derive_test.rs index ffd67b0..6d2ec94 100644 --- a/tiny-cli/tests/derive_test.rs +++ b/tiny-cli/tests/derive_test.rs @@ -167,8 +167,8 @@ Required argument 'pos_two' not supplied.", #[derive(ArgParse)] #[cli(help_path = "tiny-cli")] pub struct MultiArgOptLast { - pos_one: String, - pos_two: i64, + pub pos_one: String, + pub(crate) pos_two: i64, pos_three: Option, }