Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit c992804

Browse files
authored
More specific help message for --completions and an example for builtins to aid with testing it (#60)
1 parent e20a2f8 commit c992804

6 files changed

Lines changed: 30 additions & 9 deletions

crates/figue/examples/builtins.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use figue::{self as args, FigueBuiltins};
2+
use facet::Facet;
3+
4+
#[derive(Facet, Debug)]
5+
struct Args {
6+
/// Your actual arguments
7+
#[facet(args::positional)]
8+
filename: String,
9+
10+
/// Provides standard CLI options like --help, --version and --completions
11+
#[facet(flatten)]
12+
builtins: FigueBuiltins,
13+
}
14+
15+
fn main() {
16+
// The builtins are automatically available. They will print their help, version or completion
17+
// script and then exit.
18+
let args: Args = figue::from_std_args().unwrap();
19+
println!("A regular argument was provided: {}", args.filename);
20+
}
21+

crates/figue/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ pub struct FigueBuiltins {
400400
#[facet(args::named, args::short = 'V', args::version, default)]
401401
pub version: bool,
402402

403-
/// Generate shell completions.
403+
/// Generate shell completions for Bash, Fish, or Zsh.
404404
#[facet(args::named, args::completions, default)]
405405
pub completions: Option<Shell>,
406406
}

crates/figue/tests/integration/snapshots/main__integration__help__help_simple_struct.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: tests/integration/help.rs
2+
source: crates/figue/tests/integration/help.rs
33
expression: "$crate :: common ::\nstrip_binary_paths(& $crate :: common :: strip_ansi(& help))"
44
---
55
myapp 1.0.0
@@ -27,4 +27,4 @@ OPTIONS:
2727
-V, --version
2828
Show version and exit.
2929
--completions <SHELL>
30-
Generate shell completions.
30+
Generate shell completions for Bash, Fish, or Zsh.

crates/figue/tests/integration/snapshots/main__integration__help__help_with_subcommands.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: tests/integration/help.rs
2+
source: crates/figue/tests/integration/help.rs
33
expression: "$crate :: common ::\nstrip_binary_paths(& $crate :: common :: strip_ansi(& help))"
44
---
55
git 2.40.0
@@ -15,7 +15,7 @@ OPTIONS:
1515
-V, --version
1616
Show version and exit.
1717
--completions <SHELL>
18-
Generate shell completions.
18+
Generate shell completions for Bash, Fish, or Zsh.
1919

2020
COMMANDS:
2121
clone

crates/figue/tests/integration/snapshots/main__integration__help__subcommand_root_help.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: tests/integration/help.rs
2+
source: crates/figue/tests/integration/help.rs
33
expression: "$crate :: common ::\nstrip_binary_paths(& $crate :: common :: strip_ansi(& help))"
44
---
55
<PROGRAM>
@@ -15,7 +15,7 @@ OPTIONS:
1515
-V, --version
1616
Show version and exit.
1717
--completions <SHELL>
18-
Generate shell completions.
18+
Generate shell completions for Bash, Fish, or Zsh.
1919

2020
COMMANDS:
2121
install

crates/figue/tests/integration/snapshots/main__integration__help__tuple_variant_main_help.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
source: tests/integration/help.rs
2+
source: crates/figue/tests/integration/help.rs
33
expression: "$crate :: common ::\nstrip_binary_paths(& $crate :: common :: strip_ansi(& help))"
44
---
55
myapp
@@ -13,7 +13,7 @@ OPTIONS:
1313
-V, --version
1414
Show version and exit.
1515
--completions <SHELL>
16-
Generate shell completions.
16+
Generate shell completions for Bash, Fish, or Zsh.
1717

1818
COMMANDS:
1919
build

0 commit comments

Comments
 (0)