Skip to content

Commit cc77231

Browse files
authored
Merge pull request #449 from pacak/rc-0.9.25
Release 0.9.25
2 parents 466fcc8 + 5daead8 commit cc77231

16 files changed

Lines changed: 227 additions & 30 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bpaf"
3-
version = "0.9.24"
3+
version = "0.9.25"
44
edition = "2021"
55
categories = ["command-line-interface"]
66
description = "A simple Command Line Argument Parser with parser combinators"

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## bpaf [0.9.25] - 2026-04-15
4+
- Change rendering of an adjacent block in Markdown - this is no longer a `###`
5+
but a regular line item instead. Header messes up with generated navigation on
6+
some pages
7+
- `app_name` - parser that extracts the executable name
8+
39
## bpaf [0.9.24] - 2026-03-13
410
- a less confusing error message when invalid user input mixes with parsers that
511
can succeed with no input, see #442

docs2/src/appname/cases.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Parsed application name doesn't show up in the `--help` output
2+
3+
> --help
4+
5+
but simply produces the app name, when it is available
6+
7+
> --user=Bob

docs2/src/appname/combine.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
use bpaf::*;
3+
#[derive(Debug, Clone)]
4+
pub struct Options {
5+
user: String,
6+
appname: String,
7+
}
8+
9+
pub fn options() -> OptionParser<Options> {
10+
let user = short('u')
11+
.long("user")
12+
.help("Specify user name")
13+
// you can specify exact type argument should produce
14+
// for as long as it implements `FromStr`
15+
.argument::<String>("NAME");
16+
17+
construct!(Options { user, appname() }).to_options()
18+
}

docs2/src/appname/derive.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
use bpaf::*;
3+
#[derive(Debug, Clone, Bpaf)]
4+
#[bpaf(options)]
5+
pub struct Options {
6+
/// Specify user name
7+
#[bpaf(short, long, argument::<String>("NAME"))]
8+
user: String,
9+
10+
/// Specify user age
11+
#[bpaf(external)]
12+
appname: String,
13+
}

examples/app_name.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use bpaf::*;
2+
#[derive(Debug, Clone)]
3+
pub struct Options {
4+
user: String,
5+
appname: String,
6+
}
7+
8+
pub fn options() -> OptionParser<Options> {
9+
let user = short('u')
10+
.long("user")
11+
.help("Specify user name")
12+
// you can specify exact type argument should produce
13+
// for as long as it implements `FromStr`
14+
.argument::<String>("NAME");
15+
16+
construct!(Options { user, appname() }).to_options()
17+
}
18+
19+
fn main() {
20+
let opts = options().run();
21+
println!("{opts:?}");
22+
}

src/buffer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ pub(crate) enum Block {
275275
/// level 3 section header, "group_help" header, etc.
276276
Section3,
277277

278+
// 2 margin
279+
/// Same as level 3, but with no `###` in markdown
280+
Section4,
281+
278282
// inline, 4 margin, no nesting
279283
/// -h, --help
280284
ItemTerm,

src/buffer/console.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl Doc {
271271
pending_newline = true;
272272
margins.push(margin);
273273
}
274-
Block::Section3 => {
274+
Block::Section3 | Block::Section4 => {
275275
pending_newline = true;
276276
margins.push(margin + 2);
277277
}
@@ -310,6 +310,7 @@ impl Doc {
310310
Block::Header
311311
| Block::Section2
312312
| Block::Section3
313+
| Block::Section4
313314
| Block::ItemTerm
314315
| Block::DefinitionList
315316
| Block::Meta

src/buffer/html.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ impl Doc {
259259
res.push_str("<p>");
260260
}
261261
Block::Meta => todo!(),
262-
Block::Section3 => res.push_str("<div style='padding-left: 0.5em'>"),
262+
Block::Section3 | Block::Section4 => {
263+
res.push_str("<div style='padding-left: 0.5em'>")
264+
}
263265
Block::Mono | Block::TermRef => {}
264266
Block::InlineBlock => {
265267
skip.push();
@@ -294,7 +296,7 @@ impl Doc {
294296
res.push_str("</p>");
295297
}
296298
Block::Mono | Block::TermRef => {}
297-
Block::Section3 => res.push_str("</div>"),
299+
Block::Section3 | Block::Section4 => res.push_str("</div>"),
298300
Block::Meta => todo!(),
299301
}
300302
}
@@ -395,7 +397,7 @@ impl Doc {
395397
Block::Section2 => {
396398
res.push_str("");
397399
}
398-
Block::ItemTerm => {
400+
Block::ItemTerm | Block::Section4 => {
399401
new_markdown_line(&mut res);
400402
empty_term = matches!(
401403
self.tokens.get(ix + 1),
@@ -431,7 +433,11 @@ impl Doc {
431433
Token::BlockEnd(b) => {
432434
change_to_markdown_style(&mut res, &mut cur_style, Styles::default());
433435
match b {
434-
Block::Header | Block::Block | Block::Section3 | Block::Section2 => {
436+
Block::Header
437+
| Block::Block
438+
| Block::Section3
439+
| Block::Section2
440+
| Block::Section4 => {
435441
res.push('\n');
436442
}
437443

src/buffer/manpage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl Doc {
190190
Token::BlockStart(block) => {
191191
//
192192
match block {
193-
Block::Header | Block::Section2 | Block::Section3 => {
193+
Block::Header | Block::Section2 | Block::Section3 | Block::Section4 => {
194194
capture.1 = true;
195195
}
196196
Block::ItemTerm => {
@@ -218,7 +218,7 @@ impl Doc {
218218
roff.control("SH", [capture.0.to_uppercase()]);
219219
capture.0.clear();
220220
}
221-
Block::Section2 | Block::Section3 => {
221+
Block::Section2 | Block::Section3 | Block::Section4 => {
222222
capture.1 = false;
223223
roff.control("SS", [capture.0.to_uppercase()]);
224224
capture.0.clear();

0 commit comments

Comments
 (0)