Skip to content

Commit fa29b12

Browse files
authored
Merge pull request #408 from pacak/rc-0.9.16
Release 0.9.16
2 parents 068f514 + b81bbba commit fa29b12

File tree

7 files changed

+57
-5
lines changed

7 files changed

+57
-5
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bpaf"
3-
version = "0.9.15"
3+
version = "0.9.16"
44
edition = "2021"
55
categories = ["command-line-interface"]
66
description = "A simple Command Line Argument Parser with parser combinators"
@@ -21,7 +21,7 @@ include = [
2121

2222

2323
[dependencies]
24-
bpaf_derive = { path = "./bpaf_derive", version = "=0.5.13", optional = true }
24+
bpaf_derive = { path = "./bpaf_derive", version = "=0.5.16", optional = true }
2525
owo-colors = { version = ">=3.5, <5.0", default-features = false, optional = true }
2626
supports-color = { version = ">=2.0.0, <4.0", optional = true }
2727

Changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## bpaf [0.9.16], 2025-01-24
4+
- treat `pure` as an implicit consumer - don't add unnecessary `.optional()` or `.many()`
5+
- unbrainfart one of the examples
6+
37
## bpaf [0.9.15], 2024-10-08
48
- a fix for a previous fix of fish completions, again - regenerate the files
59

bpaf_derive/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bpaf_derive"
3-
version = "0.5.13"
3+
version = "0.5.16"
44
edition = "2018"
55
categories = ["command-line-interface"]
66
description = "Derive macros for bpaf Command Line Argument Parser"

bpaf_derive/src/field_tests.rs

+36
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,42 @@ fn positional_bool() {
950950
assert_eq!(input.to_token_stream().to_string(), output.to_string());
951951
}
952952

953+
#[test]
954+
fn pure_optional_named() {
955+
let input: NamedField = parse_quote! {
956+
#[bpaf(pure(x))]
957+
flag: Option<Vec<X>>
958+
};
959+
let output = quote! {
960+
::bpaf::pure(x)
961+
};
962+
assert_eq!(input.to_token_stream().to_string(), output.to_string());
963+
}
964+
965+
#[test]
966+
fn pure_vec_named() {
967+
let input: NamedField = parse_quote! {
968+
#[bpaf(pure(x))]
969+
flag: Vec<X>
970+
};
971+
let output = quote! {
972+
::bpaf::pure(x)
973+
};
974+
assert_eq!(input.to_token_stream().to_string(), output.to_string());
975+
}
976+
977+
#[test]
978+
fn pure_optional_pos() {
979+
let input: UnnamedField = parse_quote! {
980+
#[bpaf(pure(x))]
981+
Option<Vec<X>>
982+
};
983+
let output = quote! {
984+
::bpaf::pure(x)
985+
};
986+
assert_eq!(input.to_token_stream().to_string(), output.to_string());
987+
}
988+
953989
#[test]
954990
fn raw_literal() {
955991
let input: NamedField = parse_quote! {

bpaf_derive/src/named_field.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl StructField {
280280
let span = ty.span();
281281

282282
if !(postpr.iter().any(|p| matches!(p, Post::Parse(_)))
283-
|| matches!(cons, Consumer::External { .. }))
283+
|| matches!(cons, Consumer::External { .. } | Consumer::Pure { .. }))
284284
{
285285
match shape {
286286
Shape::Optional(_) => postpr.insert(0, Post::Parse(PostParse::Optional { span })),

examples/env_logger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn verbose() -> impl Parser<LevelFilter> {
3232
.count()
3333
.map(|l| {
3434
use LevelFilter::*;
35-
[Off, Error, Warn, Info, Debug, Trace][l.max(5)]
35+
[Off, Error, Warn, Info, Debug, Trace][l.clamp(0, 5)]
3636
})
3737
}
3838

tests/derive.rs

+12
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,15 @@ Available commands:
123123
let r = parser.run_inner(&["one"]).unwrap();
124124
assert_eq!(r, One);
125125
}
126+
127+
#[test]
128+
fn pure_optional() {
129+
#[derive(Bpaf, Debug, Clone)]
130+
#[bpaf(options)]
131+
struct Opts {
132+
#[bpaf(pure(Default::default()))]
133+
foo: Option<Vec<u32>>,
134+
}
135+
136+
assert_eq!(opts().run().foo, None);
137+
}

0 commit comments

Comments
 (0)