bpaf
A simple Command Line Argument Parser with parser combinators
0.9.27
7.4M downloads/mo
#3688 most downloaded on crates.io
pacak/bpaf
What this package is like to depend on
Last release 25 days ago
29 Jul 2026
Release timing varies
gaps range from 2 weeks to 8 months
Nearly every release is documented
notes for 64 of 68 stable releases
1 version withdrawn
withdrawn after publishing
4 years old
69 releases · first in 2022
7 releases in the last 12 months
see the full history below
Release timeline
69 releases · Mar 2022 to Jul 2026Releases
latest 60 of 69-
0.9.2729 Jul 2026Release notes
Open source →- improve error message if user passes an empty value to argument or positional
-
0.9.2613 May 2026 -
0.9.2515 Apr 2026Release notes
Open source →- Change rendering of an adjacent block in Markdown - this is no longer a
###but a regular line item instead. Header messes up with generated navigation on some pages app_name- parser that extracts the executable name
- Change rendering of an adjacent block in Markdown - this is no longer a
-
0.9.2413 Mar 2026Release notes
Open source →-
a less confusing error message when invalid user input mixes with parsers that can succeed with no input, see #442 thanks @tonky for a solution prototype
-
CI test for older rustc now uses 1.71, MSRV should still be 1.60 for now
-
-
0.9.2303 Feb 2026 -
0.9.2216 Jan 2026 -
0.9.2115 Jan 2026 -
0.9.2025 May 2025 -
0.9.1913 Mar 2025Release notes
Open source →- Fix one more problematic corner case of
fallback_to_usage- it should no override inner parser printing usage or version info
- Fix one more problematic corner case of
-
0.9.1806 Mar 2025Release notes
Open source →- Several small documentation fixes (#414, #413) thanks @yerke
fallback_to_usageonly applies if parser fails (#415) Previously it would print a usage info even if parser can succeed without any input
-
0.9.1701 Mar 2025Release notes
Open source →- A new method
format_fallbackallows to format fallback values using a custom formatting function. This extends functionality offered byformat_debugandformat_displaythat useDebugandDisplayinstances respectively thanks @antalsz
- A new method
-
0.9.1624 Jan 2025Release notes
Open source →- treat
pureas an implicit consumer - don't add unnecessary.optional()or.many() - unbrainfart one of the examples
- treat
-
0.9.1508 Oct 2024Release notes
Open source →- a fix for a previous fix of fish completions, again - regenerate the files
-
0.9.1419 Sep 2024Release notes
Open source →- add license files (#388) thanks @davide
- fix fish completions - you'll need to regenerate completion files for them to work
-
0.9.1306 Sep 2024Release notes
Open source →- You can now use
fallback_to_usagein derive macro for options and subcommands (#376) - Bugfixes related to shell completion and file masks thanks @ozwaldorf
not_strictrestriction for positional items (TODO - check the docs) thanks @ozwaldorf- more shell completion bugfixes (#384, #382, #381)
ParseFailure::print_mesage(with onesis deprecated in favor of the right spelling
- You can now use
-
0.9.1229 Apr 2024 -
0.9.1124 Mar 2024 -
0.9.1019 Mar 2024Release notes
Open source →- due to dependency change colored output for legacy version is no longer supported
- Added
OptionParser::max_widthand#[bpaf(max_width(xxx))]to specify maximum width of help output - Added a custom path attribute to allow using of reexported bpaf thanks @bzm3r
- support anywhere in bpaf_derive thanks @vallentin
- small documentation improvements thanks @Boshen
- minor shell completion improvements
- avoid panic in case of hidden but required parser argument (#345)
- somewhat breaking -
ParseFailure::exit_codeis separated intoParseFailure::exit_codeandParseFailure::print_message, one produces exit code, one prints the message
-
0.9.917 Jan 2024Release notes
Open source →- fix formatting in ambiguity error message
- relax upper range on owo-colors
-
0.9.806 Dec 2023 -
0.9.706 Dec 2023 -
0.9.630 Oct 2023Release notes
Open source →- make sure env-only arguments and flags are working
- support raw identifiers in derive macro (#282)
- better error messages for unexpected values that prevent positional parses
- bugfix in completions generator for bash thanks @akinomyoga
choicecombinator to efficiently construct alternative parsers at runtime
-
0.9.524 Aug 2023Release notes
Open source →- fancier squashing: parse
-abfooas-a -b=fooif b is a short argument bpaf_derive: make sure command aliases are actually working
- fancier squashing: parse
-
0.9.408 Aug 2023Release notes
Open source →- add
helptoParseFlagandParseArgument - stop deprecating
Parser::run - Lots of docs.rs documentation improvements
- changes to rendered markdown
- add
-
0.9.326 Jul 2023Release notes
Open source →Parser::collectallows to collect multiple items into an arbitraryFromIteratorcollection- Bugfix in parsing for unit structs
- docs.rs documentation update
-
0.9.213 Jul 2023Release notes
Open source →- with
docgenfeature you can render documentation as markdown - cosmetic changes to error messages
- with
-
0.9.105 Jul 2023Release notes
Open source →- add a way to print usage when called with no argument_os
- since 0.9.0 bpaf splits help messages into "full" and "partial", displaying
full only when
--helpflag is passed twice or when rendering the documentation, see https://docs.rs/bpaf/0.9.0/bpaf/parsers/struct.NamedArg.html#method.help display_fallbackanddebug_fallbacknow can be used withfallback_with- regression fixes
-
0.9.003 Jul 2023Release notes
Open source →- more errors are now passed as ADTs rather than plain strings
- conflicts are now tracked with indices rather than parser meta
- documentation improvements
- better error messages
- smaller generated binary
Breaking changes
bpaf_derive 0.5.0comes with some breaking changes- documentation generation now comes under
docgenfeature instead ofmanpageand some things are renamed - standalone
commandfunction was deprecated in favor of.commandmethod onOptionParser - hidden no-op helper type
FromUtf8was removed - "{usage}" override is removed in favor of new
OptionParser::with_usage
-
0.8.130 May 2023 -
0.8.011 May 2023Release notes
Open source →Breaking changes
anynow takes a function that checks if it matches the input or not. You can still apply usual filtering withguard, etc after it but initial filtering inside a function leads to better error messages.anywhereis now a method onanyinstead of being a parser method and should now be used to make an arbitrary looking flag like parsers. You can still parse blocks from arbitrary places using remainingadjacentmethodmanyandsomewill now collect one result from a parser that does not consume anything from an argument list allowing for easier composition with parsers that consume from both command line and environment variables. If your code depends on the original behavior you should replace non failing parsers undermanywith failing parsers:req_flaginstead ofswitch.
Improvements
- parsing combinators
many,some,optionalandanywherewill now propagate parsing errors outwards, you can regain the old behvior by specifyingcatch - better error messages related to
anywhereparsers anywhereparsers are now given an attempt to consume an empty list- support deriving
req_flagconsumers - support deriving
catchannotation - errors generated by
somecan now be handled withfallback/fallback_with - fallback values can be made visible in
--helpwithdisplay_fallback/debug_fallback bpaf_derive: top level doc comments on a regular parser are now turned into agroup_help- better error messages for invalid user input
- env fallback can now be fully hidden
- meta description refactor - invididual parsers should be described more consistently in all sorts of messages
- better error messages with positionals and inside anywhere blocks
Migration guide 0.7.x -> 0.8.x
- if you used
anyto consume items without validations just passSomeas a parameter and add two wildcard generic type parameters:-let rest = any<OsString>("RESt").many(); +let rest = any<OsString, _, _>("REST", Some); - If you used
anywith extra validation to decide if something should be consumed at all you can move this validation inside of any. If validation fails - any behaves as if this argument wasn't specified at all:-let name = any("NAME").guard(|x| x == "Bob", "Only Bob is allowed").optional().catch(); +let name = any("NAME", |x| (x == "Bob").then_some(x)); - You can replicate most of the behavior from old
anywheremodifier with newadjacent:-let set = construct!(set, name, value).anywhere(); +let set = construct!(set, name, value).adjacent(); - If you previously used
switchor an option with fallback in combination withmanyyou need to replaceswitchwith something that needs at least one item and move fallback outside:-let verbose = short('v').switch().many().map(|x| x.len()); +let verbose = short('v').req_flag(()).many().map(|x| x.len());
-
0.7.1019 Mar 2023Release notes
Open source →- improve error messages for typos like
-llvminstead of--llvm - improve error messages when a flag is accepted by a command but not directly
- allow to derive position bool
- derive anywhere and boxed
- dynamic layout for --help messages
- bump syn to 2.0
- improve error messages for typos like
-
0.7.914 Feb 2023 -
0.7.802 Feb 2023Release notes
Open source →- manpage generation bugfixes, thanks to @ysndr
- internal cleanups
- avoid impossible shell completions
-
0.7.704 Dec 2022 -
0.7.629 Nov 2022 -
0.7.529 Nov 2022Release notes
Open source →- improve error messages when several conflicting options are specified
- improve category theory docs
- improve docs for batteries
-
0.7.420 Nov 2022Release notes
Open source →- bpaf_derive: improve error message
- bpaf: bugfix for bash static shell completion
-
0.7.314 Nov 2022Release notes
Open source →try_runthanks to @ysndr-Obits=2048is now parsed as short flagOwith a value ofbits=2048instad of crashingcomplete_shell- a way to call to static shell completion functions, bash and zsh only for now
-
0.7.227 Oct 2022Release notes
Open source →- drop tainting logic, should be redundant
- improve error messages for guard and conflicting branches
-
0.7.115 Oct 2022Release notes
Open source →- colors similar to cargo'some thanks to @kramer425
- support for empty structs/enums in
construct!
-
0.7.011 Oct 2022Release notes
Open source →pure_withimplementation thanks to @xitepFromOsStris replaced with magical uses ofAnytraithide_usagebright-coloranddull-colorfeatures- accept fully qualified names in more places in
bpaf_derive - cosmetic improvements
- documentation improvements
Migration guide 0.6.x -> 0.7.x
- Remove FromUtf8 annotations if you have any
In many cases rustc should be able to derive what the type-let coin = short('c').argument::<FromUtf8<Coin>>("COIN"); +let coin = short('c').argument::<Coin>("COIN"); - Replace
FromOsStrimplementations for your types withFromStrif you have any. If your type requires parsingOsStringdirectly you can perform it in two steps - consumingOsString+ parsing it withParser::parse - If you want to provide your users with colored output - expose
bright-colorand/ordull-colorfeatures
-
0.6.130 Sep 2022Release notes
Open source →- cosmetic improvements
- completion info in
sensorsexample - better errors in partially consumed optional items
- better handling of -- during autcomplete
- initial release of
bpaf_cauwugo
-
0.6.023 Sep 2022Release notes
Open source →What's new in 0.6.0
adjacentrestriction to parse things in a tighter contextcatchformany,someandoptionalto handle parse errorsanypositional like, to consume pretty much anything from a command line- improved documentation with more detailed examples
- cosmetic improvements
- a sneaky reminder to use
to_optionsonParserbefore trying to run it - removed OsString specific
positional_osandargument_os - a way to make boxed parsers with single item
construct!macro for making dynamic parsers - a horrible way to reduce Yoda-talk coding by placing primitive definitions inside the
construct!macro
With new additions you should be able to parse pretty much anything and then some more :)
Migration guide 0.5.x -> 0.6.x
- Replace any uses of
positional_osandargument_oswithpositionalandargumentplus turbofish:-let file = positional_os("FILE").help("File to use").map(PathBuf::from); +let file = positional::<PathBuf>("FILE").help("File to use"); - Replace any uses of
from_strwith either turbofish on the consumer or withparse, ifStringis generated inside the parser:
You can still use it for your own types if you implement-let number = short('n').argument("N").from_str::<usize>(); +let number = short('n').argument::<usize>("N");FromOsStr, alternativelyparsestill works:-let my = long("my-type").argument("MAGIC").from_str::<MyType>(); +let my = long("my-type").argument::<String>("MAGIC").parse(|s| MyType::from_str(s)); - You shouldn't be using those names directly in your code, but there are some renames
Positional->ParsePositionalBuildArgument->ParseArgumentCommand->ParseCommandNamed->NamedArg
-
0.5.704 Sep 2022Release notes
Open source →- bugfix with zsh autocomplete #46
- reimplement bpaf derive - should be faster to compile and easier to work with
-
0.5.603 Sep 2022 -
0.5.502 Sep 2022Release notes
Open source →- invariant checker - for tests
- more error message improvements
- non-utf8 support in --foo=bar / -f=bar
- dynamic shell completion: bash, zsh, fish, elvish
- toggle flag battery
- templated usage string: can use "{usage}" in custom overrides
-
0.5.425 Aug 2022Release notes
Open source →minor bugfixes
- more consistent alternative selection
- handle "missing" inside a subparser
-
0.5.323 Aug 2022Release notes
Open source →and a bit more cosmetics - preserve suggestion context when returning from a subcommand
-
0.5.223 Aug 2022Release notes
Open source →- fix a regression in error messaged caused by 0.5.1
- guard now displays the problematic input if it's a single argument issue
-
0.5.122 Aug 2022 withdrawnRelease notes
Open source →improve error messages if argument parsing fails:
- matcher no longer escapes inner command if it gets there
- detect and try to suggest for possible typos
-
0.5.021 Aug 2022Release notes
Open source →should be faster to compile and a bit more flexible with respect to what is accepted
Braking changes
- explicit
constructannotation is gone and used by default ifoptionsandcommandare missing optionsandcommandnow must be specified at the beginning of#[bpaf(...macrodefaultannotation for enum variants is gone, you can usefallbackon top instead
- explicit
-
0.4.1208 Aug 2022 -
0.4.1107 Aug 2022 -
0.4.1006 Aug 2022 -
0.4.903 Aug 2022 -
0.4.802 Aug 2022 -
0.4.728 Jun 2022 -
0.4.628 Jun 2022Nothing published for this version
-
0.4.525 Jun 2022 -
0.4.405 Jun 2022