Skip to content

Commit d43f1db

Browse files
committed
docs: Move everything to docs.rs
A couple of things happened when preparing to release 3.0 - We needed derive documentation - I had liked how serde handled theres - I had bad experiences finding things in structopt's documentation - The examples were broken and we needed tests - The examples seemed to follow a pattern of having tutorial content and cookbook content - We had been getting bug reports from people looking at master and thinking they were looking at what is currently released - We had gotten feedback to keep down the number of places that documentation was located From this, we went with a mix of docs.rs and github - We kept the number of content locations at 2 rather than 3 by not having an external site like serde - We rewrote the examples into explicit tutorials and cookbooks to align with the 4 styles of documentation - We could test our examples by running `console` code blocks with trycmd - Documentation was versioned and the README pointed to the last release This had downsides - The tutorials didn't have the code inlined - Users still had a hard time finding and navigating between the different forms of documentation - In practice, we were less likely to cross-link between the different types of documentation Moving to docs.rs would offer a lot of benefits, even if it is only designed for Rust-reference documentation and isn't good for Rust derive reference documentation, tutorials, cookbooks, etc. The big problem was keeping the examples tested to keep maintenance costs down. Maybe its just me but its easy to overlook - You can pull documentation from a file using `#[doc = "path"]` - Repeated doc attributes get concatenated rather than first or last writer winning Remember these when specifically thinking about Rust documentation made me realize that we could get everything into docs.rs. When doing this - Tutorial code got brought in as was one of the aims - We needed to split the lib documentation and the README to have all of the linking work. This allowed us to specialize them according to their rule (user vs contributor) - We needed to avoid users getting caught up in making a decision between Derive and Builder APIs so we put the focus on the derive API with links to the FAQ to help users decide when to use one or the other. - Improved cross-referencing between different parts of the documentation - Limited inline comments were added to example code - Introductory example code intentionally does not have teaching comments in it as its meant to give a flavor or sense of things and not meant to teach on its own. This is a first attempt. There will be a lot of room for further improvement. Current know downsides: - Content source is more split up for the tutorials This hopefully addresses clap-rs#3189
1 parent a15524a commit d43f1db

File tree

95 files changed

+2293
-2125
lines changed

Some content is hidden

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

95 files changed

+2293
-2125
lines changed

README.md

Lines changed: 3 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!-- omit in TOC -->
21
# clap
32

43
> **Command Line Argument Parser for Rust**
@@ -13,149 +12,13 @@
1312

1413
Dual-licensed under [Apache 2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT).
1514

16-
1. [About](#about)
17-
2. Tutorial: [Builder API](https://github.com/clap-rs/clap/blob/v3.2.12/examples/tutorial_builder/README.md), [Derive API](https://github.com/clap-rs/clap/blob/v3.2.12/examples/tutorial_derive/README.md)
18-
3. [Examples](https://github.com/clap-rs/clap/blob/v3.2.12/examples/README.md)
19-
4. [API Reference](https://docs.rs/clap)
20-
- [Derive Reference](https://github.com/clap-rs/clap/blob/v3.2.12/examples/derive_ref/README.md)
21-
- [Feature Flags](#feature-flags)
22-
5. [CHANGELOG](https://github.com/clap-rs/clap/blob/v3.2.12/CHANGELOG.md)
23-
6. [FAQ](https://github.com/clap-rs/clap/blob/v3.2.12/docs/FAQ.md)
24-
7. [Questions & Discussions](https://github.com/clap-rs/clap/discussions)
25-
8. [Contributing](https://github.com/clap-rs/clap/blob/v3.2.12/CONTRIBUTING.md)
26-
8. [Sponsors](#sponsors)
27-
2815
## About
2916

3017
Create your command-line parser, with all of the bells and whistles, declaratively or procedurally.
3118

32-
### Example
33-
34-
Add `clap` as a dependency with the `derive` feature enabled:
35-
```console
36-
cargo add clap -F derive
37-
```
38-
39-
This allows using the
40-
[Derive API](https://github.com/clap-rs/clap/blob/v3.2.12/examples/tutorial_derive/README.md)
41-
which provides access to the [Builder API](https://github.com/clap-rs/clap/blob/v3.2.12/examples/tutorial_builder/README.md) as attributes on a `struct`:
42-
43-
<!-- Copied from examples/demo.{rs,md} -->
44-
```rust,no_run
45-
use clap::Parser;
46-
47-
/// Simple program to greet a person
48-
#[derive(Parser, Debug)]
49-
#[clap(author, version, about, long_about = None)]
50-
struct Args {
51-
/// Name of the person to greet
52-
#[clap(short, long, value_parser)]
53-
name: String,
54-
55-
/// Number of times to greet
56-
#[clap(short, long, value_parser, default_value_t = 1)]
57-
count: u8,
58-
}
59-
60-
fn main() {
61-
let args = Args::parse();
62-
63-
for _ in 0..args.count {
64-
println!("Hello {}!", args.name)
65-
}
66-
}
67-
```
68-
69-
```bash
70-
$ demo --help
71-
clap [..]
72-
Simple program to greet a person
73-
74-
USAGE:
75-
demo[EXE] [OPTIONS] --name <NAME>
76-
77-
OPTIONS:
78-
-c, --count <COUNT> Number of times to greet [default: 1]
79-
-h, --help Print help information
80-
-n, --name <NAME> Name of the person to greet
81-
-V, --version Print version information
82-
```
83-
*(version number and `.exe` extension on windows replaced by placeholders)*
84-
85-
### Aspirations
86-
87-
- Out of the box, users get a polished CLI experience
88-
- Including common argument behavior, help generation, suggested fixes for users, colored output, [shell completions](https://github.com/clap-rs/clap/tree/master/clap_complete), etc
89-
- Flexible enough to port your existing CLI interface
90-
- However, we won't necessarily streamline support for each use case
91-
- Reasonable parse performance
92-
- Resilient maintainership, including
93-
- Willing to break compatibility rather than batching up breaking changes in large releases
94-
- Leverage feature flags to keep to one active branch
95-
- Being under [WG-CLI](https://github.com/rust-cli/team/) to increase the bus factor
96-
- We follow semver and will wait about 6-9 months between major breaking changes
97-
- We will support the last two minor Rust releases (MSRV, currently 1.56.1)
98-
99-
While these aspirations can be at odds with fast build times and low binary
100-
size, we will still strive to keep these reasonable for the flexibility you
101-
get. Check out the
102-
[argparse-benchmarks](https://github.com/rust-cli/argparse-benchmarks-rs) for
103-
CLI parsers optimized for other use cases.
104-
105-
### Selecting an API
106-
107-
Why use the declarative [Derive API](https://github.com/clap-rs/clap/blob/v3.2.12/examples/tutorial_derive/README.md):
108-
- Easier to read, write, and modify
109-
- Easier to keep the argument declaration and reading of argument in sync
110-
- Easier to reuse, e.g. [clap-verbosity-flag](https://crates.io/crates/clap-verbosity-flag)
111-
112-
Why use the procedural [Builder API](https://github.com/clap-rs/clap/blob/v3.2.12/examples/tutorial_builder/README.md):
113-
- Faster compile times if you aren't already using other procedural macros
114-
- More flexible, e.g. you can look up how many times an argument showed up,
115-
what its values were, and what were the indexes of those values. The Derive
116-
API can only report presence, number of occurrences, or values but no indices
117-
or combinations of data.
118-
119-
### Related Projects
120-
121-
- [wild](https://crates.io/crates/wild) for supporting wildcards (`*`) on Windows like you do Linux
122-
- [argfile](https://crates.io/crates/argfile) for loading additional arguments from a file (aka response files)
123-
- [shadow-rs](https://crates.io/crates/shadow-rs) for generating `Command::long_version`
124-
- [clap_lex](https://crates.io/crates/clap_lex) for a lighter-weight, battle-tested CLI parser
125-
- [clap_mangen](https://crates.io/crates/clap_mangen) for generating man page source (roff)
126-
- [clap_complete](https://crates.io/crates/clap_complete) for shell completion support
127-
- [clap-verbosity-flag](https://crates.io/crates/clap-verbosity-flag)
128-
- [clap-cargo](https://crates.io/crates/clap-cargo)
129-
- [concolor-clap](https://crates.io/crates/concolor-clap)
130-
- [Command-line Apps for Rust](https://rust-cli.github.io/book/index.html) book
131-
- [`trycmd`](https://crates.io/crates/trycmd): Snapshot testing
132-
- Or for more control, [`assert_cmd`](https://crates.io/crates/assert_cmd) and [`assert_fs`](https://crates.io/crates/assert_fs)
133-
134-
## Feature Flags
135-
136-
### Default Features
137-
138-
* **std**: _Not Currently Used._ Placeholder for supporting `no_std` environments in a backwards compatible manner.
139-
* **color**: Turns on colored error messages.
140-
* **suggestions**: Turns on the `Did you mean '--myoption'?` feature for when users make typos.
141-
142-
#### Optional features
143-
144-
* **deprecated**: Guided experience to prepare for next breaking release (at different stages of development, this may become default)
145-
* **derive**: Enables the custom derive (i.e. `#[derive(Parser)]`). Without this you must use one of the other methods of creating a `clap` CLI listed above.
146-
* **cargo**: Turns on macros that read values from `CARGO_*` environment variables.
147-
* **env**: Turns on the usage of environment variables during parsing.
148-
* **regex**: Enables regex validators.
149-
* **unicode**: Turns on support for unicode characters (including emoji) in arguments and help messages.
150-
* **wrap_help**: Turns on the help text wrapping feature, based on the terminal size.
151-
152-
#### Experimental features
153-
154-
**Warning:** These may contain breaking changes between minor releases.
155-
156-
* **unstable-replace**: Enable [`Command::replace`](https://github.com/clap-rs/clap/issues/2836)
157-
* **unstable-grouped**: Enable [`ArgMatches::grouped_values_of`](https://github.com/clap-rs/clap/issues/2924)
158-
* **unstable-v4**: Preview features which will be stable on the v4.0 release
19+
For more details, see:
20+
- [docs.rs](https://docs.rs/clap/latest/clap/)
21+
- [examples](examples/)
15922

16023
## Sponsors
16124

docs/FAQ.md

Lines changed: 0 additions & 76 deletions
This file was deleted.

examples/README.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

examples/cargo-example-derive.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
*Jump to [source](cargo-example-derive.rs)*
2-
31
For more on creating a custom subcommand, see [the cargo
42
book](https://doc.rust-lang.org/cargo/reference/external-tools.html#custom-subcommands).
53
The crate [`clap-cargo`](https://github.com/crate-ci/clap-cargo) can help in

examples/cargo-example-derive.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// Note: this requires the `derive` feature
2-
31
use clap::Parser;
42

5-
#[derive(Parser)]
3+
#[derive(Parser)] // requires `derive` feature
64
#[clap(name = "cargo")]
75
#[clap(bin_name = "cargo")]
86
enum Cargo {

examples/cargo-example.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
*Jump to [source](cargo-example.rs)*
2-
31
For more on creating a custom subcommand, see [the cargo
42
book](https://doc.rust-lang.org/cargo/reference/external-tools.html#custom-subcommands).
53
The crate [`clap-cargo`](https://github.com/crate-ci/clap-cargo) can help in

examples/cargo-example.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Note: this requires the `cargo` feature
2-
31
fn main() {
42
let cmd = clap::Command::new("cargo")
53
.bin_name("cargo")

examples/demo.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
*Jump to [source](demo.rs)*
2-
3-
**This requires enabling the `derive` feature flag.**
4-
5-
Used to validate README.md's content
61
```console
72
$ demo --help
83
clap [..]
@@ -17,4 +12,8 @@ OPTIONS:
1712
-n, --name <NAME> Name of the person to greet
1813
-V, --version Print version information
1914

15+
$ demo --name Me
16+
Hello Me!
17+
2018
```
19+
*(version number and `.exe` extension on windows replaced by placeholders)*

examples/demo.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Note: this requires the `derive` feature
2-
31
use clap::Parser;
42

53
/// Simple program to greet a person

0 commit comments

Comments
 (0)