Skip to content

Commit

Permalink
Merge pull request #259 from pacak/rc-0.9.4
Browse files Browse the repository at this point in the history
Update more documentation
  • Loading branch information
pacak authored Aug 6, 2023
2 parents 9c56e78 + 27b0c90 commit babd3e6
Show file tree
Hide file tree
Showing 34 changed files with 264 additions and 875 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/target
Cargo.lock
.xwin-cache/
/docs/src/*.rs
/tarp
/dotfiles
/legacy/target
Expand Down
10 changes: 0 additions & 10 deletions docs/src/boxed/cases.txt

This file was deleted.

28 changes: 0 additions & 28 deletions docs/src/boxed/combine.rs

This file was deleted.

26 changes: 0 additions & 26 deletions docs/src/dd/cases.txt

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/dd/example.rs

This file was deleted.

46 changes: 0 additions & 46 deletions docs/src/find/cases.txt

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/find/example.rs

This file was deleted.

27 changes: 0 additions & 27 deletions docs/src/numeric_prefix/cases.txt

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/numeric_prefix/example.rs

This file was deleted.

25 changes: 0 additions & 25 deletions docs/src/xorg/cases.txt

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/xorg/example.rs

This file was deleted.

10 changes: 10 additions & 0 deletions docs2/src/boxed/cases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
It is also possible to make dynamic choice about the parsers. This example defines two parsers
for distance - imperial and metric and picks one from some source available at runtime only.

Help message will contain only one parser

> --help
and only one parser will produce a result

> --distance 10
26 changes: 26 additions & 0 deletions docs2/src/boxed/combine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
use bpaf::*;

pub fn options() -> OptionParser<f64> {
let miles = long("distance")
.help("distance in miles")
.argument::<f64>("MILES")
.map(|d| d * 1.609344);

let km = long("distance")
.help("distance in km")
.argument::<f64>("KM");

// suppose this is reading from config fule
let use_metric = true;

// without use of `boxed` here branches have different types so it won't typecheck
// boxed make it so branches have the same type as long as they return the same type
let distance = if use_metric {
km.boxed()
} else {
miles.boxed()
};

distance.to_options()
}
16 changes: 16 additions & 0 deletions docs2/src/numeric_prefix/cases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
If `bpaf` can parse first positional argument as number - it becomes a numeric prefix

> 10 eat
Otherwise it gets ignored

> "just eat"

If validation passes but second argument is missing - in this example there's no fallback

> 10
Help should show that the prefix is optional

> --help
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Lets you do things like `setup.py sdist bdist`: [command chaining](https://click
With [`adjacent`](crate::parsers::ParseCommand::adjacent)
`bpaf` allows you to have several commands side by side instead of being nested.

#![cfg_attr(not(doctest), doc = include_str!("docs/adjacent_2.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/adjacent_command.md"))]
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
By default arguments take at most one value, you can create multi value options by using
[`adjacent`](crate::parsers::ParseCon::adjacent) modifier

#![cfg_attr(not(doctest), doc = include_str!("docs/adjacent_0.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/adjacent_struct_0.md"))]
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ overwriting previous one.
--sensor-i2c-address=0x49 \
```

#![cfg_attr(not(doctest), doc = include_str!("docs/adjacent_1.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/adjacent_struct_1.md"))]
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
So you can parse things while parsing things. Not sure why you might need this, but you can
:)

#![cfg_attr(not(doctest), doc = include_str!("docs/adjacent_4.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/adjacent_struct_4.md"))]
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### Skipping optional positional items if parsing or validation fails

#![cfg_attr(not(doctest), doc = include_str!("docs/numeric_prefix.md"))]
Combinations like [`Parser::optional`] and
[`ParseOptional::catch`](crate::parsers::ParseOptional::catch) allow to try to parse something
and then handle the error as if pase attempt never existed

#![cfg_attr(not(doctest), doc = include_str!("docs2/numeric_prefix.md"))]
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### Implementing cargo commands

With [`cargo_helper`](crate::batteries::cargo_helper) you can use your application as a `cargo` command
With [`cargo_helper`](crate::batteries::cargo_helper) you can use your application as a `cargo` command.
You will need to enable `batteries` feature while importing `bpaf`.

#![cfg_attr(not(doctest), doc = include_str!("docs/cargo_helper.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/cargo_helper.md"))]
19 changes: 12 additions & 7 deletions src/_documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2246,7 +2246,7 @@
//! With [`adjacent`](crate::parsers::ParseCommand::adjacent)
//! `bpaf` allows you to have several commands side by side instead of being nested.
//!
#![cfg_attr(not(doctest), doc = include_str!("docs/adjacent_2.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/adjacent_command.md"))]
//!
//!
//! &nbsp;
Expand Down Expand Up @@ -2297,7 +2297,7 @@
//! By default arguments take at most one value, you can create multi value options by using
//! [`adjacent`](crate::parsers::ParseCon::adjacent) modifier
//!
#![cfg_attr(not(doctest), doc = include_str!("docs/adjacent_0.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/adjacent_struct_0.md"))]
//!
//!
//! &nbsp;
Expand Down Expand Up @@ -2364,7 +2364,7 @@
//! --sensor-i2c-address=0x49 \
//! ```
//!
#![cfg_attr(not(doctest), doc = include_str!("docs/adjacent_1.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/adjacent_struct_1.md"))]
//!
//!
//! &nbsp;
Expand Down Expand Up @@ -2415,7 +2415,7 @@
//! So you can parse things while parsing things. Not sure why you might need this, but you can
//! :)
//!
#![cfg_attr(not(doctest), doc = include_str!("docs/adjacent_4.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/adjacent_struct_4.md"))]
//!
//!
//! &nbsp;
Expand Down Expand Up @@ -2463,7 +2463,11 @@
//!
//! #### Skipping optional positional items if parsing or validation fails
//!
#![cfg_attr(not(doctest), doc = include_str!("docs/numeric_prefix.md"))]
//! Combinations like [`Parser::optional`] and
//! [`ParseOptional::catch`](crate::parsers::ParseOptional::catch) allow to try to parse something
//! and then handle the error as if pase attempt never existed
//!
#![cfg_attr(not(doctest), doc = include_str!("docs2/numeric_prefix.md"))]
//!
//!
//! &nbsp;
Expand Down Expand Up @@ -2511,9 +2515,10 @@
//!
//! #### Implementing cargo commands
//!
//! With [`cargo_helper`](crate::batteries::cargo_helper) you can use your application as a `cargo` command
//! With [`cargo_helper`](crate::batteries::cargo_helper) you can use your application as a `cargo` command.
//! You will need to enable `batteries` feature while importing `bpaf`.
//!
#![cfg_attr(not(doctest), doc = include_str!("docs/cargo_helper.md"))]
#![cfg_attr(not(doctest), doc = include_str!("docs2/cargo_helper.md"))]
//!
//!
//! &nbsp;
Expand Down
Loading

0 comments on commit babd3e6

Please sign in to comment.