Skip to content

Commit 6f01ee0

Browse files
authored
Merge pull request #378 from pacak/ftu
`fallback_to_usage` fixes related to an `enum` of commands
2 parents fc14443 + 44386a7 commit 6f01ee0

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

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

611
## bpaf [0.9.12] - 2024-04-29
712
- better error messages

bpaf_derive/src/top.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl ParsedEnumBranch {
507507

508508
if let Some(opts_at) = has_options {
509509
if fallback_usage {
510-
attrs.push(EAttr::FallbackUsage);
510+
attrs.insert(opts_at, EAttr::FallbackUsage);
511511
}
512512

513513
if let Some(h) = std::mem::take(&mut help) {

bpaf_derive/src/top_tests.rs

+26
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,32 @@ fn fallback_usage_subcommand() {
7272
assert_eq!(input.to_token_stream().to_string(), expected.to_string());
7373
}
7474

75+
#[test]
76+
fn fallback_usage_lut() {
77+
let input: Top = parse_quote! {
78+
#[bpaf(options)]
79+
enum Lutgen {
80+
/// descr
81+
#[bpaf(command, fallback_to_usage)]
82+
Generate,
83+
}
84+
};
85+
86+
let expected = quote! {
87+
fn lutgen() -> ::bpaf::OptionParser<Lutgen> {
88+
#[allow(unused_imports)]
89+
use ::bpaf::Parser;
90+
::bpaf::pure(Lutgen::Generate)
91+
.to_options()
92+
.descr("descr")
93+
.fallback_to_usage()
94+
.command("generate")
95+
.to_options()
96+
}
97+
};
98+
assert_eq!(input.to_token_stream().to_string(), expected.to_string());
99+
}
100+
75101
#[test]
76102
fn top_struct_construct() {
77103
let top: Top = parse_quote! {

0 commit comments

Comments
 (0)