Skip to content

Commit

Permalink
Merge pull request #408 from pacak/rc-0.9.16
Browse files Browse the repository at this point in the history
Release 0.9.16
  • Loading branch information
pacak authored Jan 24, 2025
2 parents 068f514 + b81bbba commit fa29b12
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bpaf"
version = "0.9.15"
version = "0.9.16"
edition = "2021"
categories = ["command-line-interface"]
description = "A simple Command Line Argument Parser with parser combinators"
Expand All @@ -21,7 +21,7 @@ include = [


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

Expand Down
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## bpaf [0.9.16], 2025-01-24
- treat `pure` as an implicit consumer - don't add unnecessary `.optional()` or `.many()`
- unbrainfart one of the examples

## bpaf [0.9.15], 2024-10-08
- a fix for a previous fix of fish completions, again - regenerate the files

Expand Down
2 changes: 1 addition & 1 deletion bpaf_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bpaf_derive"
version = "0.5.13"
version = "0.5.16"
edition = "2018"
categories = ["command-line-interface"]
description = "Derive macros for bpaf Command Line Argument Parser"
Expand Down
36 changes: 36 additions & 0 deletions bpaf_derive/src/field_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,42 @@ fn positional_bool() {
assert_eq!(input.to_token_stream().to_string(), output.to_string());
}

#[test]
fn pure_optional_named() {
let input: NamedField = parse_quote! {
#[bpaf(pure(x))]
flag: Option<Vec<X>>
};
let output = quote! {
::bpaf::pure(x)
};
assert_eq!(input.to_token_stream().to_string(), output.to_string());
}

#[test]
fn pure_vec_named() {
let input: NamedField = parse_quote! {
#[bpaf(pure(x))]
flag: Vec<X>
};
let output = quote! {
::bpaf::pure(x)
};
assert_eq!(input.to_token_stream().to_string(), output.to_string());
}

#[test]
fn pure_optional_pos() {
let input: UnnamedField = parse_quote! {
#[bpaf(pure(x))]
Option<Vec<X>>
};
let output = quote! {
::bpaf::pure(x)
};
assert_eq!(input.to_token_stream().to_string(), output.to_string());
}

#[test]
fn raw_literal() {
let input: NamedField = parse_quote! {
Expand Down
2 changes: 1 addition & 1 deletion bpaf_derive/src/named_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl StructField {
let span = ty.span();

if !(postpr.iter().any(|p| matches!(p, Post::Parse(_)))
|| matches!(cons, Consumer::External { .. }))
|| matches!(cons, Consumer::External { .. } | Consumer::Pure { .. }))
{
match shape {
Shape::Optional(_) => postpr.insert(0, Post::Parse(PostParse::Optional { span })),
Expand Down
2 changes: 1 addition & 1 deletion examples/env_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn verbose() -> impl Parser<LevelFilter> {
.count()
.map(|l| {
use LevelFilter::*;
[Off, Error, Warn, Info, Debug, Trace][l.max(5)]
[Off, Error, Warn, Info, Debug, Trace][l.clamp(0, 5)]
})
}

Expand Down
12 changes: 12 additions & 0 deletions tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,15 @@ Available commands:
let r = parser.run_inner(&["one"]).unwrap();
assert_eq!(r, One);
}

#[test]
fn pure_optional() {
#[derive(Bpaf, Debug, Clone)]
#[bpaf(options)]
struct Opts {
#[bpaf(pure(Default::default()))]
foo: Option<Vec<u32>>,
}

assert_eq!(opts().run().foo, None);
}

0 comments on commit fa29b12

Please sign in to comment.