Skip to content

Commit 80f0372

Browse files
committed
more feedback
1 parent bc8dac8 commit 80f0372

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

code/organizing-binary/src/command.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use clap::Parser;
55
#[derive(Debug, Parser)]
66
pub struct MyApp {
77
// Options, subcommands etc
8+
#[clap(short, long, default_value_t)]
9+
my_arg: usize,
810
}
911

1012
impl MyApp {
1113
pub fn exec(self) -> color_eyre::Result<()> {
12-
// execute the command and return a result
13-
unimplemented!()
14+
println!("The value of my-arg is {}", self.my_arg);
15+
Ok(())
1416
}
1517
}

src/acknowledgments.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
Thanks to the following reviewers who read through drafts of this document and provided invaluable feedback:
44

5-
- Manish Goregaokar ([Twitter](https://twitter.com/ManishEarth), [GitHub](https://github.com/Manishearth))
65
- Ana Hobden ([Twitter](https://twitter.com/a_hoverbear), [GitHub](https://github.com/hoverbear))
6+
- Ed Page ([GitHub](https://github.com/epage))
7+
- Inanna Malick ([Twitter](https://twitter.com/inanna_malick/), [GitHub](https://github.com/inanna-malick))
78
- jam1garner ([Twitter](https://twitter.com/jam1garner), [GitHub](https://github.com/jam1garner))
89
- Jane Lusby ([Twitter](https://twitter.com/yaahc_), [GitHub](https://github.com/yaahc))
9-
- Inanna Malick ([Twitter](https://twitter.com/inanna_malick/), [GitHub](https://github.com/inanna-malick))
10-
- Ed Page ([GitHub](https://github.com/epage))
10+
- Manish Goregaokar ([Twitter](https://twitter.com/ManishEarth), [GitHub](https://github.com/Manishearth))

src/colors.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Terminals use the same escape codes to support both colors and styles---bold, it
4141

4242
**Applications *must not* use blinking text.** Blinking text can be distracting or difficult to read for many people. The HTML `<blink>` tag, which had similar behavior, was [removed from web pages](https://www.fastcompany.com/3015408/saying-goodbye-to-the-html-tag) around 2013.
4343

44+
> TODO: add information about ASCII and Unicode symbols (including emoji) that are safe to use in terminals.
45+
4446
## ANSI color codes and Windows color APIs
4547

4648
Most Unix terminals support [ANSI color codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors). For example, turning the foreground color to "green" involves writing the characters `\x1b` (ESC), `[`, `32` (for green), and `m` to the terminal.

src/hierarchical-config.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ Exactly how deep merges should go is application-specific.
4646

4747
There are two main Rust libraries for managing hierarchical configuration:
4848

49-
* [config](https://crates.io/crates/config). I've used this and it seems to work well.
50-
* [figment](https://crates.io/crates/figment). This seems quite nice as well, though I haven't used it.
49+
* [config](https://crates.io/crates/config). I've used this for my own projects.
50+
* [figment](https://crates.io/crates/figment). Seems high quality, though I haven't used it.
5151

52-
These configuration libraries can be used in combination with serde, so that you can manage hierarchies and merges with dynamically typed variables at the edges of your program, then switch over to well-typed serde structures for the rest of your code. For how to do this with config, [see this example].
52+
These configuration libraries can be used in combination with serde, so that you can manage hierarchies and merges with dynamically typed variables at the edges of your program, then switch over to well-typed serde structures for validating the config's schema. For how to do this with config, [see this example].
5353

5454
[see this example]: https://github.com/mehcode/config-rs/blob/53e43fbcf96b5c2a661d052a6e3d55fc3709f1e1/examples/hierarchical-env/settings.rs

src/organizing-binary.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ Within a binary crate, here's the organization that's *recommended*.
1414
{{#rustdoc_include ../code/organizing-binary/src/lib.rs}}
1515
```
1616

17-
`my-app/src/main.rs`:
17+
`my-app/src/bin/my-app.rs`:
1818
```rust
19-
{{#rustdoc_include ../code/organizing-binary/src/main.rs}}
19+
{{#rustdoc_include ../code/organizing-binary/src/bin/my-app.rs}}
2020
```
2121

2222
Notes:
2323
* **Most of the logic is within `command.rs`.**
2424
* In general, you *should* keep lib.rs as minimal as possible, unless your entire library fits in it. That's
2525
because all methods and fields in `lib.rs` are visible to the entire library---code in the top-level module
2626
cannot be marked private to the rest of the module.
27-
* **There's a `lib.rs` separate from the `main.rs`.**
28-
* This is because `rustdoc` doesn't use standard privacy rules if building documentation from `main.rs`,
29-
so private modules are visible in the public documentation.
27+
* **There's a `lib.rs` separate from the `my-app.rs` that contains `main`.**
28+
* There are several advantages to having a `lib.rs`. In particular, `rustdoc` doesn't use standard privacy rules if building documentation from `main.rs`, so private modules are visible in the public documentation.
3029
* **Only the top-level `MyApp` is exported.**
3130
* The top-level `MyApp` is all `main.rs` should generally need to care about.
3231
* **`MyApp` is marked `#[doc(hidden)]`.**
3332
* The details of `MyApp` are only meant to be seen by `main`. The library is not part of the public API. Only
3433
the command-line interface is.
34+
* **`src/bin/my-app.rs` instead of `src/main.rs`.**
35+
* While `src/main.rs` works just as well, `src/bin` makes it harder to accidentally import library code with `mod` statements.

src/versioning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ A binary crate *should* define its public API as consisting of the command-line
1414
* Mark old commands or arguments deprecated, and possibly hide them from help text. Continue to preserve their behavior.
1515
* If the program persists data on disk, make it possible to do forward transitions but not backward ones. Add a *format version* to persisted data and increment it every time the data format changes. If an old version of the program reads a format version it does not understand, error out gracefully.
1616

17-
> Tip: You can use the [baptiste0928/cargo-install](https://github.com/baptiste0928/cargo-install) Cargo action to install a binary from crates.io, caching it if possible. This action lets you specify a version range, which plays well with the above binary versioning policy.
17+
> Tip: If you're using GitHub Actions for CI, use the [baptiste0928/cargo-install](https://github.com/baptiste0928/cargo-install) action to install a binary from crates.io, using a cached version if possible. This action lets you specify a version range, which plays well with the binary versioning policy above.

0 commit comments

Comments
 (0)