### Install bpaf_cauwugo Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Install the bpaf_cauwugo tool using cargo. ```bash $ cargo install bpaf_cauwugo ``` -------------------------------- ### Running Example Source: https://github.com/pacak/bpaf/blob/master/README.md Demonstrates how to run examples from the bpaf repository using cargo. ```shell $ cargo run --example example_name ``` -------------------------------- ### cauwugo test completion for bins, tests, and examples Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Shows autocompletion for testable items like bins, tests, and examples with cauwugo test. ```bash % cauwugo test [skip] Bins, tests, examples adjacent bpaf bpaf_derive derive help_format % cauwugo test de % cauwugo test derive % cauwugo test derive Available test names command_and_fallback help_with_default_parse % cauwugo test derive co % cauwugo test derive command_and_fallback ``` -------------------------------- ### Dynamic Build Target Completion for `cauwugo build` Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Shows dynamic completion for build examples and target architectures. It also lists available targets. ```console % cauwugo build --example se ``` ```console % cauwugo build --example sensors ``` ```console % cauwugo build --example sensros --target ``` ```console % cauwugo build --example sensors --target ``` ```console armv7-unknown-linux-gnueabihf x86_64-pc-windows-gnu x86_64-unknown-linux-gnu ``` ```console % cauwugo build --example sensors --target a ``` ```console % cauwugo build --example sensors --target armv7-unknown-linux-gnueabihf ``` -------------------------------- ### cauwugo test execution example Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Illustrates the output after running a specific test using cauwugo test. ```text Finished test [unoptimized + debuginfo] target(s) in 0.00s Running tests/derive.rs (target/debug/deps/derive-7ef117342dbf6a84) running 1 test test command_and_fallback ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out; finished in 0.00s ``` -------------------------------- ### Feature Flags for Color Output Source: https://github.com/pacak/bpaf/blob/master/README.md Example of how to expose color features as feature flags in your Cargo.toml for conditional compilation. ```toml [features] bright-color = ["bpaf/bright-color"] dull-color = ["bpaf/dull-color"] ``` -------------------------------- ### Generate Zsh Completion Script Source: https://github.com/pacak/bpaf/blob/master/README.md Redirect the output of your program with the --bpaf-complete-style-zsh flag to a file in your zsh completions directory, ensuring the filename starts with an underscore. ```console $ your_program --bpaf-complete-style-zsh > ~/.zsh/_your_program ``` -------------------------------- ### Define arguments using bpaf combinatoric API Source: https://github.com/pacak/bpaf/blob/master/README.md Construct argument parsers programmatically using combinators. This example defines speed and distance arguments and combines them into a struct. ```rust use bpaf::{construct, long, Parser}; #[derive(Clone, Debug)] struct SpeedAndDistance { /// Speed in KPH speed: f64, /// Distance in miles distance: f64, } fn main() { // primitive parsers let speed = long("speed") .help("Speed in KPH") .argument::("SPEED"); let distance = long("distance") .help("Distance in miles") .argument::("DIST"); // parser containing information about both speed and distance let parser = construct!(SpeedAndDistance { speed, distance }); // option parser with metainformation attached let speed_and_distance = parser .to_options() .descr("Accept speed and distance, print them"); let opts = speed_and_distance.run(); println!("Options: {:?}", opts); } ``` -------------------------------- ### Define arguments using bpaf derive API Source: https://github.com/pacak/bpaf/blob/master/README.md Use the `#[derive(Bpaf)]` macro to automatically generate argument parsing code from a struct definition. This example defines speed and distance arguments. ```rust use bpaf::Bpaf; #[derive(Clone, Debug, Bpaf)] #[bpaf(options, version)] /// Accept speed and distance, print them struct SpeedAndDistance { /// Speed in KPH speed: f64, /// Distance in miles distance: f64, } fn main() { // #[derive(Bpaf)] generates `speed_and_distance` function let opts = speed_and_distance().run(); println!("Options: {:?}", opts); } ``` -------------------------------- ### Dynamic Package Completion for `cauwugo add` Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Demonstrates dynamic completion for package names when adding a dependency. It also shows completion for workspace members. ```console % cauwugo add serde serde A generic serialization/deserialization framework serde_alias An attribute macro to apply serde aliases to all struct fields serde_amqp A serde implementation of AMQP1.0 protocol. serde_any Dynamic serialization and deserialization with the format chosen at runtime serde_asn1_der A basic ASN.1-DER implementation for `serde` based upon `asn1_der` serde-big-array Big array helper for serde. ``` ```console % cauwugo add serde_j ``` ```console % cauwugo add serde_j ``` ```console % cauwugo add serde_json -p bpaf bpaf_cauwugo bpaf_derive docs ``` ```console % cauwugo add serde_json -p ``` ```console % cauwugo add serde_json -p ``` ```console % cauwugo add serde_json -p bpaf_cauwugo ``` -------------------------------- ### Configure Shell Completions Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Enable shell completions for bpaf_cauwugo by running the appropriate command for your shell. This only needs to be done once. ```bash $ cauwugo --bpaf-complete-style-bash ``` ```bash $ cauwugo --bpaf-complete-style-zsh ``` ```bash $ cauwugo --bpaf-complete-style-fish ``` ```bash $ cauwugo --bpaf-complete-style-elvish ``` -------------------------------- ### cauwugo clean package completion Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Demonstrates how cauwugo autocompletes package names for the 'clean' command. ```bash % cauwugo clean --p % cauwugo clean --package % cauwugo clean --package d % cauwugo clean --package docs ``` -------------------------------- ### cauwugo run passthrough completion Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Demonstrates passthrough argument completion for the 'cauwugo run' command when using bpaf with dynamic completion. ```bash % cauwugo run se % cauwugo run sensors % cauwugo run sensors -- --sensor --sensor-device --sensor-i2c-address
--sensor-name % cauwugo run sensors -- --sensor --sensor-device elakelaiset% cauwugo run sensors -- --sensor-device outdoor ~/ej/bpaf outdoor Outdoor temperature sensor tank01 Temperature in a storage tank 1 tank02 Temperature in a storage tank 2 tank03 Temperature in a storage tank 3 temp100 Main temperature sensor temp101 Output temperature sensor ``` -------------------------------- ### Enable bpaf autocomplete for cauwugo run Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Configuration snippet to enable bpaf argument completion for cauwugo run within the workspace metadata. ```toml [workspace.metadata.cauwugo] bpaf = true # use true if all the executables/examples use bpaf or a list of packages if only some are ``` -------------------------------- ### Generate Fish Completion Script Source: https://github.com/pacak/bpaf/blob/master/README.md Redirect the output of your program with the --bpaf-complete-style-fish flag to the appropriate completions directory for fish shell. ```console $ your_program --bpaf-complete-style-fish > ~/.config/fish/completions/your_program.fish ``` -------------------------------- ### Enable bpaf Completion Passthrough Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Configure your workspace to enable completion passthrough for bpaf-enabled packages. This requires adding a configuration to your Cargo.toml file. ```toml [workspace.metadata.cauwugo] bpaf = true ``` -------------------------------- ### Generate Elvish Completion Script Source: https://github.com/pacak/bpaf/blob/master/README.md Append the output of your program with the --bpaf-complete-style-elvish flag to your elvish rc file. ```console $ your_program --bpaf-complete-style-elvish >> ~/.config/elvish/rc.elv ``` -------------------------------- ### Generate Bash Completion Script Source: https://github.com/pacak/bpaf/blob/master/README.md Redirect the output of your program with the --bpaf-complete-style-bash flag to a file in your bash completion directory. ```console $ your_program --bpaf-complete-style-bash >> ~/.bash_completion ``` -------------------------------- ### Enable Autocomplete Feature Source: https://github.com/pacak/bpaf/blob/master/README.md Add the 'autocomplete' feature to your bpaf dependency in Cargo.toml to enable shell completion capabilities. ```toml bpaf = { version = "0.9", features = ["autocomplete"] } ``` -------------------------------- ### View Cargo Zsh Completion File Source: https://github.com/pacak/bpaf/blob/master/bpaf_cauwugo/README.md Display the contents of the Zsh completion file provided by Cargo. This file contains static completion definitions for commands and flags. ```bash % cat "$(rustc --print sysroot)"/share/zsh/site-functions/_cargo ``` -------------------------------- ### Replace positional_os/argument_os with positional/argument Source: https://github.com/pacak/bpaf/blob/master/Changelog.md In version 0.6.x, `positional_os` and `argument_os` have been replaced by `positional` and `argument` respectively. Use turbofish syntax for type annotation. ```diff -let file = positional_os("FILE").help("File to use").map(PathBuf::from); +let file = positional::("FILE").help("File to use"); ``` -------------------------------- ### Add bpaf to Cargo.toml for combinatoric API Source: https://github.com/pacak/bpaf/blob/master/README.md Include bpaf in your project's dependencies without specific features for the combinatoric API. ```toml [dependencies] bpaf = "0.9" ``` -------------------------------- ### Test Parser with run_inner Source: https://github.com/pacak/bpaf/blob/master/README.md Tests a parser's help output using the run_inner function. Ensure the Options struct is defined with #[derive(Bpaf)]. ```rust #[derive(Debug, Clone, Bpaf)] #[bpaf(options)] pub struct Options { pub user: String } #[test] fn test_my_options() { let help = options() .run_inner(&["--help"]) .unwrap_err() .unwrap_stdout(); let expected_help = "\ Usage --user=ARG "; assert_eq!(help, expected_help); } ``` -------------------------------- ### Replace from_str with turbofish or parse Source: https://github.com/pacak/bpaf/blob/master/Changelog.md The `from_str` method is deprecated. Use turbofish on the consumer or the `parse` method if `String` is generated within the parser. For custom types, ensure `FromOsStr` is implemented or use `parse` with a custom conversion. ```diff -let number = short('n').argument("N").from_str::(); +let number = short('n').argument::("N"); ``` ```diff -let my = long("my-type").argument("MAGIC").from_str::(); +let my = long("my-type").argument::("MAGIC").parse(|s| MyType::from_str(s)); ``` -------------------------------- ### Migrate `any` to new signature in bpaf Source: https://github.com/pacak/bpaf/blob/master/Changelog.md When migrating from older versions of bpaf, update the `any` function signature to include generic type parameters and a closure for validation. This change improves error handling and flexibility. ```rust let rest = any("REST", Some); ``` ```rust let name = any("NAME", |x| (x == "Bob").then_some(x)); ``` -------------------------------- ### Add bpaf with derive feature to Cargo.toml Source: https://github.com/pacak/bpaf/blob/master/README.md Include bpaf in your project's dependencies, enabling the 'derive' feature for the derive API. ```toml [dependencies] bpaf = { version = "0.9", features = ["derive"] } ``` -------------------------------- ### Migrate FromUtf8 Annotation Source: https://github.com/pacak/bpaf/blob/master/Changelog.md Update code by removing FromUtf8 annotations for type parsing. This change simplifies type handling in bpaf. ```diff ```diff -let coin = short('c').argument::>("COIN"); +let coin = short('c').argument::("COIN"); ``` ``` -------------------------------- ### Parser with validation and transformation Source: https://github.com/pacak/bpaf/blob/master/README.md Defines a parser for speed that includes validation guards to ensure the value is within a specific range (0.0 to 100.0) and then transforms the parsed f64 into a custom Speed struct. ```rust #[derive(Clone, Debug)] struct Speed(f64); fn speed() -> impl Parser { long("speed") .help("Speed in KPH") .argument::("SPEED") // You can perform additional validation with `parse` and `guard` functions // in as many steps as required. // Before and after next two applications the type is still `impl Parser` .guard(|&speed| speed >= 0.0, "You need to buy a DLC to move backwards") .guard(|&speed| speed <= 100.0, "You need to buy a DLC to break the speed limits") // You can transform contained values, next line gives `impl Parser` as a result .map(|speed| Speed(speed)) } ``` -------------------------------- ### Define a basic speed parser Source: https://github.com/pacak/bpaf/blob/master/README.md A regular function that defines a parser for a single floating-point number argument named 'speed'. This function can be shared across different parts of your application. ```rust fn speed() -> impl Parser { long("speed") .help("Speed in KPH") .argument::("SPEED") } ``` -------------------------------- ### Update `many` with `req_flag` in bpaf Source: https://github.com/pacak/bpaf/blob/master/Changelog.md If you previously used `switch` or an option with fallback in combination with `many`, replace `switch` with `req_flag` and move the fallback logic outside the `many` combinator to ensure correct behavior. ```rust let verbose = short('v').req_flag(()).many().map(|x| x.len()); ``` -------------------------------- ### Parse multiple speed arguments Source: https://github.com/pacak/bpaf/blob/master/README.md This parser accepts multiple occurrences of the '--speed' flag from the command line, collecting all provided values into a vector. ```rust fn multiple_args() -> impl Parser> { speed().many() } ``` -------------------------------- ### Rename types: Positional, BuildArgument, Command, Named Source: https://github.com/pacak/bpaf/blob/master/Changelog.md Several types have been renamed in version 0.6.x for clarity. Ensure your code reflects these changes: `Positional` to `ParsePositional`, `BuildArgument` to `ParseArgument`, `Command` to `ParseCommand`, and `Named` to `NamedArg`. -------------------------------- ### Parse speed argument with a fallback value Source: https://github.com/pacak/bpaf/blob/master/README.md This parser checks for the presence of '--speed'. If the flag is not provided, it defaults to a value of 42.0. ```rust fn with_fallback() -> impl Parser { speed().fallback(42.0) } ``` -------------------------------- ### Replace `anywhere` with `adjacent` in bpaf Source: https://github.com/pacak/bpaf/blob/master/Changelog.md In bpaf version 0.8.0 and later, the `anywhere` modifier has been replaced by the `adjacent` method. Use `adjacent` to replicate the behavior of parsing blocks from arbitrary places. ```rust let set = construct!(set, name, value).adjacent(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.