Skip to content

Commit

Permalink
Merge pull request #378 from pacak/ftu
Browse files Browse the repository at this point in the history
`fallback_to_usage` fixes related to an `enum` of commands
  • Loading branch information
pacak authored Jul 25, 2024
2 parents fc14443 + 44386a7 commit 6f01ee0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## bpaf [0.9.13] - Unreleased
- You can now use `fallback_to_usage` in derive macro for options and subcommands
- Bugfixes related to shell completion and file masks
thanks @ozwaldorf
- `not_strict` restriction for positional items (TODO - check the docs)
thanks @ozwaldorf


## bpaf [0.9.12] - 2024-04-29
- better error messages
Expand Down
2 changes: 1 addition & 1 deletion bpaf_derive/src/top.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ impl ParsedEnumBranch {

if let Some(opts_at) = has_options {
if fallback_usage {
attrs.push(EAttr::FallbackUsage);
attrs.insert(opts_at, EAttr::FallbackUsage);
}

if let Some(h) = std::mem::take(&mut help) {
Expand Down
26 changes: 26 additions & 0 deletions bpaf_derive/src/top_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ fn fallback_usage_subcommand() {
assert_eq!(input.to_token_stream().to_string(), expected.to_string());
}

#[test]
fn fallback_usage_lut() {
let input: Top = parse_quote! {
#[bpaf(options)]
enum Lutgen {
/// descr
#[bpaf(command, fallback_to_usage)]
Generate,
}
};

let expected = quote! {
fn lutgen() -> ::bpaf::OptionParser<Lutgen> {
#[allow(unused_imports)]
use ::bpaf::Parser;
::bpaf::pure(Lutgen::Generate)
.to_options()
.descr("descr")
.fallback_to_usage()
.command("generate")
.to_options()
}
};
assert_eq!(input.to_token_stream().to_string(), expected.to_string());
}

#[test]
fn top_struct_construct() {
let top: Top = parse_quote! {
Expand Down

0 comments on commit 6f01ee0

Please sign in to comment.