Skip to content

Commit ceeaadb

Browse files
committed
docs: improve guides, navigation, and landing page
Entire-Checkpoint: 01M1TH0VF6GAKBD4QC4V849FQ0
1 parent 4f7a324 commit ceeaadb

52 files changed

Lines changed: 1466 additions & 943 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# Contributing
22

3-
See the [contributing guide](https://usage.jdx.dev/contributing).
3+
The [contributing guide](https://usage.jdx.dev/contributing) covers project scope,
4+
review expectations, and checks. Start from the repository root:
5+
6+
```sh
7+
mise install
8+
mise run build
9+
mise run test
10+
```
11+
12+
For website changes, run `mise run docs:dev` for a live preview and
13+
`mise exec -- aube run docs:build` for the production build. Guides live in
14+
`docs/`; `docs/cli/reference/` is generated from command help in the Rust source.
415

516
## mbx build cache
617

@@ -9,12 +20,12 @@ See the [contributing guide](https://usage.jdx.dev/contributing).
920
its transparent Cargo wrapper and therefore use the cache while invoking Cargo
1021
normally. Standalone Cargo commands require an activated mise shell. To bypass
1122
mbx without skipping or weakening a check, prefix the
12-
equivalent Cargo command with `MBX_DISABLE=1`:
23+
equivalent Cargo command with `MBX_DISABLE=1` and keep the mise tool environment:
1324

1425
```sh
15-
MBX_DISABLE=1 cargo build --all
16-
MBX_DISABLE=1 cargo test --all --all-features
17-
MBX_DISABLE=1 cargo clippy --all --all-features --all-targets -- -D warnings
26+
MBX_DISABLE=1 mise exec -- cargo build --all
27+
MBX_DISABLE=1 mise exec -- cargo test --all --all-features
28+
MBX_DISABLE=1 mise exec -- cargo clippy --all --all-features --all-targets -- -D warnings
1829
```
1930

2031
If bypassed Cargo succeeds where the wrapper fails, or mbx introduces a papercut, please start a

NOTICE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Third-party notices
22

3-
Usage itself is licensed under the MIT License; see [LICENSE](LICENSE). This file
3+
Usage itself is licensed under the MIT License; see [LICENSE](https://github.com/jdx/usage/blob/main/LICENSE). This file
44
records the third-party work that Usage vendors, derives from, or is closely
55
modeled on, together with the license each is used under.
66

@@ -44,7 +44,7 @@ warrant attribution:
4444
- `usage-derive` / `usage-rs` deliberately mirror `clap_derive`'s attribute
4545
vocabulary and semantics (`long`, `short`, `env`, `default_value`, `flatten`,
4646
`value_enum`, `rename_all`, and friends) so a clap declaration can be ported
47-
field by field. See [docs/rust/migrating-from-clap.md](docs/rust/migrating-from-clap.md).
47+
field by field. See [docs/rust/migrating-from-clap.md](https://github.com/jdx/usage/blob/main/docs/rust/migrating-from-clap.md).
4848
- The rendered help, usage line, and diagnostic conventions follow clap's output
4949
shape so migrated CLIs keep their existing user-facing text.
5050
- `clap_usage` reads a `clap::Command` through clap's public API to generate a
@@ -84,7 +84,7 @@ The Apache-2.0 option is available upstream at
8484

8585
`benches/shadows/external-*` and `conformance/tests/external_clap_adopters.rs`
8686
are reductions of three real clap-based CLIs, pinned to the revisions recorded in
87-
[benches/external/README.md](benches/external/README.md). They are reduced rather
87+
[benches/external/README.md](https://github.com/jdx/usage/blob/main/benches/external/README.md). They are reduced rather
8888
than vendored, but they do carry each upstream's declaration shapes and help text,
8989
so each upstream's license is reproduced below.
9090

README.md

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
# Usage
22

3-
Usage is a spec, CLI, and Rust framework for defining command-line interfaces.
4-
Arguments, flags, environment variables, and config files can all be described in
5-
a portable KDL spec. Think of it as [OpenAPI](https://www.openapis.org/) for CLIs:
6-
one declaration can drive parsing and every user-facing artifact.
3+
**Define your CLI once. Generate the tools around it.**
74

8-
- Generate shell completions
9-
- Generate Markdown documentation and man pages
10-
- Parse arguments from any language
11-
- Scaffold a spec into CLI frameworks in different languages
12-
- Build a typed Rust CLI with a zero-dependency runtime
5+
Usage is a portable [KDL](https://kdl.dev/) specification, a command-line utility,
6+
and a Rust framework. Describe commands, flags, arguments, and settings in one
7+
place, then use that definition for parsing, help, shell completions, Markdown
8+
docs, man pages, and typed clients.
139

14-
See more at [usage.jdx.dev](https://usage.jdx.dev/).
10+
[Get started](https://usage.jdx.dev/guide/getting-started) ·
11+
[Rust framework](https://usage.jdx.dev/rust/) ·
12+
[Spec reference](https://usage.jdx.dev/spec/reference/) ·
13+
[CLI reference](https://usage.jdx.dev/cli/reference/)
14+
15+
| Your starting point | How Usage fits |
16+
| --------------------- | -------------------------------------------------------------------------------------------- |
17+
| A new Rust CLI | Derive a typed parser and exportable spec from structs and enums. |
18+
| An existing CLI | [Export a spec](https://usage.jdx.dev/spec/integrations) from your framework, or write KDL. |
19+
| A script | [Declare arguments in comments](https://usage.jdx.dev/cli/scripts) and let Usage parse them. |
20+
| Code that calls a CLI | [Generate a TypeScript or Python SDK](https://usage.jdx.dev/cli/sdk). |
1521

1622
## Rust framework
1723

@@ -48,6 +54,46 @@ and value variants. See the [Rust framework guide](https://usage.jdx.dev/rust/)
4854
and [clap migration guide](https://usage.jdx.dev/rust/migrating-from-clap) for
4955
the supported mappings and intentional differences.
5056

57+
## Standalone CLI
58+
59+
Choose one installation method:
60+
61+
```sh
62+
# mise
63+
mise use -g usage
64+
65+
# Homebrew
66+
brew install usage
67+
68+
# Cargo
69+
cargo install usage-cli --locked
70+
```
71+
72+
The package is `usage-cli`; the executable is `usage`.
73+
[Other installation options](https://usage.jdx.dev/cli/#installation).
74+
75+
With a spec saved as `mycli.usage.kdl`:
76+
77+
```sh
78+
usage lint mycli.usage.kdl
79+
usage generate completion zsh mycli --file mycli.usage.kdl --install
80+
usage generate markdown --file mycli.usage.kdl --out-file reference.md
81+
usage generate manpage --file mycli.usage.kdl --out-file mycli.1
82+
```
83+
84+
The generated shell scripts need `usage` at completion time. The Rust framework
85+
can also [provide completions directly](https://usage.jdx.dev/rust/completions)
86+
from your binary.
87+
88+
Follow the [spec walkthrough](https://usage.jdx.dev/guide/getting-started) for a
89+
complete example. The [Go framework](https://usage.jdx.dev/go/) is a development
90+
preview and is not ready for adoption or testing.
91+
92+
## Contributing
93+
94+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, checks, and generated
95+
files.
96+
5197
## Sponsors
5298

5399
<p align="center">

clap_usage/README.md

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,55 @@
11
# clap_usage
22

3-
Generates [usage spec](https://usage.jdx.dev) for CLIs written with [clap](https://crates.io/crates/clap).
3+
Export a [Usage spec](https://usage.jdx.dev/spec/) from a
4+
[clap](https://crates.io/crates/clap) command definition. Use the spec to generate
5+
shell completions, Markdown documentation, man pages, and SDKs.
46

5-
## Usage
7+
## Add the integration
8+
9+
```toml
10+
[dependencies]
11+
clap = "4"
12+
clap_usage = "5"
13+
```
14+
15+
Expose a hidden flag that prints the spec:
616

717
```rust
8-
use clap::{arg, Command, ValueHint};
9-
use clap_usage::generate;
10-
use std::io::BufWriter;
18+
use clap::{Arg, ArgAction, Command};
1119

1220
fn build_cli() -> Command {
1321
Command::new("example")
14-
.arg(arg!(--file <FILE> "some input file").value_hint(ValueHint::AnyPath))
15-
.arg(arg!(--usage))
22+
.arg(Arg::new("file").long("file"))
23+
.arg(
24+
Arg::new("usage-spec")
25+
.long("usage-spec")
26+
.hide(true)
27+
.action(ArgAction::SetTrue),
28+
)
1629
}
1730

1831
fn main() {
19-
let matches = build_cli().get_matches();
20-
21-
if matches.get_flag("usage") {
22-
let mut cmd = build_cli();
23-
eprintln!("Generating usage spec...");
24-
clap_usage::generate(&mut cmd, "example", &mut std::io::stdout()).unwrap();
32+
let mut cmd = build_cli();
33+
let matches = cmd.clone().get_matches();
34+
if matches.get_flag("usage-spec") {
35+
clap_usage::generate(&mut cmd, "example", &mut std::io::stdout());
2536
return;
2637
}
27-
28-
// Your CLI code here...
38+
// Run the application using `matches`.
2939
}
3040
```
41+
42+
With the executable and the [Usage CLI](https://usage.jdx.dev/cli/#installation)
43+
on `PATH`:
44+
45+
```sh
46+
example --usage-spec > example.usage.kdl
47+
usage generate markdown --file example.usage.kdl --out-file reference.md
48+
usage generate completion zsh example --usage-cmd "example --usage-spec" --install
49+
```
50+
51+
The exporter can only read behavior exposed by clap's public getters. Use
52+
`spec_with_report` or `generate_with_report` to inspect detectable losses before
53+
relying on the generated interface. See the
54+
[integration guide](https://usage.jdx.dev/spec/integrations/clap) for reports,
55+
compatibility limits, and completion setup.

corpus/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# The argv conformance corpus
22

3-
> Two neighbours have corpora of their own: resolving a CLI's _configuration_
4-
> layers, precedence, merge policies — is [`config/`](config/README.md), and what a
5-
> spec _reads as_ — the usage line, `-h`, `--help` — is
6-
> [`render/`](render/README.md). This file is about parsing a command line.
3+
Related corpora cover [configuration resolution](config/README.md),
4+
[help rendering](render/README.md), and [completion](complete/README.md).
75

86
Test vectors for [the argv grammar](https://usage.jdx.dev/spec/argv). Each one
97
pairs a spec with a command line and the result parsing them must produce.

corpus/complete/README.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The completion corpus
22

3-
> The corpus two directories up is about what a command line _binds_;
3+
> The corpus one directory up is about what a command line _binds_;
44
> [`render/`](../render/README.md) is about what a spec _reads as_; [`config/`](../config/README.md)
55
> is about resolving a CLI's settings. This one is about what could go where the cursor is.
66
@@ -11,22 +11,16 @@ Plain JSON, for the same reason the others are: an implementation in any languag
1111
without reimplementing a test format. If you are answering `complete` from a usage spec — in Go,
1212
in JavaScript, or as a second Rust implementation — this directory is the definition of correct.
1313

14-
## Why this exists
14+
## Scope
1515

16-
Completion is the one area with three implementations and no shared fixture. Parsing has the
17-
corpus above; rendering got one in `render/`; completion has `argv/src/complete.rs` tested by its
18-
own unit tests, `cli/src/cli/complete_word.rs` tested by its own, and a Go implementation landed
19-
in #984 tested by a third set. Three sets of tests written against three readings of the same
20-
rules is the arrangement that produced every drift this project has had to chase — the help
21-
renderers agreed on mise and differed on five of the other six CLIs until #972 held them to one
22-
fixture.
16+
The Rust and Go completion implementations share these expectations instead of
17+
maintaining separate interpretations of candidate selection. Vectors cover
18+
incomplete input, cursor position, restart tokens, and boundaries where a command
19+
forwards input to an external program.
2320

24-
It also closes the two easier thirds of the corpus gaps that were still open: completion
25-
parsing, which is `parse_partial` over deliberately incomplete input, and restart tokens, which
26-
only matter at a cursor. Mounts remain uncovered, and deliberately — resolving one _runs a
27-
command_, which a corpus cannot do hermetically. The differential fuzzer learned that the
28-
expensive way: its first draft spawned real `mise` processes that fetched vfox metadata and
29-
shelled out to `apt-cache`.
21+
Mount resolution is excluded because it runs a command. Filesystem and dynamic
22+
completion are represented by their kind rather than by running external
23+
commands or depending on the test machine's files.
3024

3125
## What a vector says
3226

@@ -81,3 +75,15 @@ Every vector carries a `reference` label, defaulting to `agrees`, saying whether
8175
the reference implementation — produces exactly this. A vector the reference disagrees with must
8276
say so and why, so a divergence is a recorded decision rather than a mystery. That is the same
8377
rule the argv corpus runs on, and `conformance/tests/complete.rs` is what enforces it.
78+
79+
## Run the corpus
80+
81+
From the repository root:
82+
83+
```sh
84+
mise exec -- cargo test -p usage-conformance --test complete
85+
```
86+
87+
Add vectors for new completion rules and run the suite before changing a recorded
88+
reference result. See the [argv corpus](../README.md) for the shared divergence
89+
contract.

0 commit comments

Comments
 (0)