Skip to content

Commit 8203651

Browse files
kianmengsunshowers
authored andcommitted
Fix markdown issues and add linter to CI
Found via `markdownlint -f --disable MD004 MD013 MD033 MD036 MD042 -- **/*.md` See a detailed description of the rules is available at https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md Also added `markdowlint` to CI pipeline.
1 parent 6ba302d commit 8203651

15 files changed

+46
-2
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ jobs:
1515
env:
1616
RUSTFLAGS: -D warnings
1717
steps:
18-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v3
1919
with:
2020
ref: ${{ github.event.pull_request.head.sha }}
21+
- uses: DavidAnson/markdownlint-cli2-action@v10
22+
with:
23+
command: config
24+
globs: |
25+
.markdownlint.yaml
26+
'**/*.md'
2127
- uses: actions-rs/toolchain@v1
2228
with:
2329
toolchain: stable

.markdownlint.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# markdownlint configuration
2+
MD004: false
3+
MD013: false
4+
MD033: false
5+
MD036: false
6+
MD042: false

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ git clone https://github.com/sunshowers-code/rust-cli-recommendations --branch g
2020

2121
then pointing your web browser at `rust-cli-recommendations/index.html`.
2222

23-
2423
Pull requests to fix typos or unclear language are welcome! If you have a suggestion for a change to the document, please [search through the issues] to see if it's been discussed already. If not, please [open an issue].
2524

2625
[search through the issues]: https://github.com/sunshowers-code/rust-cli-recommendations/issues?q=is%3Aissue+sort%3Aupdated-desc

src/SUMMARY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@
33
- [Introduction](../README.md)
44
- [Picking an argument parser](./cli-parser.md)
55
- [Handling arguments and subcommands](./handling-arguments.md)
6+
67
---
8+
79
- [Binaries vs libraries](./binaries-vs-libraries.md)
810
- [Machine-readable output](./machine-readable-output.md)
911
- [Organizing code in binary crates](./organizing-binary.md)
1012
- [Versioning](./versioning.md)
13+
1114
---
15+
1216
- [Adding colors to applications](./colors.md)
1317
- [Managing colors in Rust](./managing-colors-in-rust.md)
1418

1519
- [Configuration](./configuration.md)
1620
- [Hierarchical configuration](./hierarchical-config.md)
1721
- [Merging command-line arguments and config files]()
22+
1823
---
24+
1925
- [Dry runs and the interpreter pattern]()
2026
- [Logging]()
2127
- [Error handling and exit codes]()

src/binaries-vs-libraries.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
You *may* expose your application's functionality as a library. Some binaries are simple and don't necessarily need to expose their functionality as a library. Other binaries are more complex, in which case their functionality can be exposed as a library that others can build upon.
44

55
**Why separate libraries from binaries?**
6+
67
* For other consumers of the library, clap and other binary-only dependencies are unnecessary.
78
* The binary's versioning is separated out from the library's versioning; see [Versioning](versioning.html) for more.
89

910
**Reasons against exposing a library**
11+
1012
* Maintaining a library in addition to a binary is hard work. It involves documentation and versioning.
1113
* In some cases, maintainers can decide to expose their functionality *only* as a binary to force a looser coupling with downstream consumers.
1214
* *Case study:* The presence of the [libgit2](https://libgit2.org/) and [JGit](https://www.eclipse.org/jgit/) libraries for Git has made it significantly harder to improve Git's data structures. These libraries are tightly coupled to their consumers, which in practice means that Git improvements are tied to the release schedules of commercial projects like Xcode and Visual Studio.
@@ -17,14 +19,17 @@ You *may* expose your application's functionality as a library. Some binaries ar
1719
> Note: In this section, "package" means all code scoped to a single `Cargo.toml` file.
1820
1921
If your code is meant to be uploaded to a registry like crates.io:
22+
2023
* Binary packages *must not* expose their library functionality within the same package.
2124
* The library package *must* be separated out, with an appropriate name linking the two.
2225

2326
If your code is internal to the workspace:
27+
2428
* Binary packages *should not* expose a library within the same package.
2529
* The library package *should* be separated out, with an appropriate name linking the two.
2630

2731
Some examples of linked names:
32+
2833
* *my-lib* for the library, and *my-lib-cli* for the binary, if most people are going to use the library.
2934
* *my-app-core* for the library, and *my-app* for the binary, if most people are going to use the binary.
3035
* *my-utility* for the library, and *cargo-my-utility* for the binary, if your program is a Cargo plugin.

src/cli-parser.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ When you're writing a Rust command-line application, one of the first things you
44
There are a number of different command-line parsers for Rust programs. However, projects *should* use [**clap**](https://crates.io/crates/clap).
55

66
**Why?**
7+
78
* clap is actively maintained: as of January 2022, clap just came out with a [v3 release]().
89
* clap is the most popular command-line parsing library for Rust, which means that there's an existing ecosystem of projects around clap.
910
* clap comes with a number of extra features, such as suggestions based on [Jaro–Winkler distance](https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance) and full configurability of [commands](https://docs.rs/clap/latest/clap/enum.AppSettings.html) and [arguments](https://docs.rs/clap/latest/clap/enum.ArgSettings.html).
1011
* There are a number of standard conventions for Unix CLIs: see [this comment](https://github.com/google/argh/issues/3#issuecomment-581144181) by [Stephen Sokolow](https://github.com/ssokolow). clap supports all of them. Another actively maintained project, [argh](https://github.com/google/argh), does not target Unix platforms and so does not support all of these conventions.
1112

1213
**Reasons against using clap**
14+
1315
* clap pulls in several dependencies and takes quite a while to build.
1416
* clap increases binary size significantly.
1517
* clap is a complex parser with many different options. I've found uses for most of them, but they can be overwhelming.
@@ -32,10 +34,12 @@ The doc comments are processed as help text by clap. Here's what the help text l
3234
```
3335

3436
**Why?**
37+
3538
* Derive-style arguments are significantly easier to read, write, and modify.
3639
* Derive-style components can be written once, and reused across multiple commands.
3740

3841
**Why not?**
42+
3943
* The derive macro is an optional feature that pulls in extra dependencies and increases build times.
4044
* The derive macro can be a bit magical. Looking at [the source code of clap_derive](https://github.com/clap-rs/clap/blob/master/clap_derive/src/lib.rs), or the generated output with [cargo-expand](https://crates.io/crates/cargo-expand), may be useful.
4145
* The derive macro is less flexible than the builder API. For example, for an argument used multiple times like `-v -v -v`, the builder API can tell you exactly which position each `-v` was used in. The derive macro can only tell you how many times `-v` was used.
@@ -45,6 +49,7 @@ The doc comments are processed as help text by clap. Here's what the help text l
4549
## Command and argument case
4650

4751
Following Unix and GNU conventions, all commands and arguments, except for short arguments, *must* be in [kebab case](https://en.wikipedia.org/wiki/Kebab_case). This means that:
52+
4853
* Commands and arguments *must* be in lowercase.
4954
* Multiple words *must* be separated by hyphens: `--example-opt`, not `--example_opt` or `--exampleOpt`.
5055

src/colors.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ These rules apply to all command-line programs, not just Rust ones.
2020
## Color palettes
2121

2222
Terminals may support one of three color palettes:
23+
2324
* *16 colors:* 4-bit color; black, red, green, yellow, blue, magenta, cyan, white, and a "bright" version of each.
2425
* *256 colors:* 8-bit color; the 16 colors above, a 6×6×6 cube for each of red, green and blue, and 24 grayscale tones. [This page by Pádraig Brady](http://www.pixelbeat.org/docs/terminal_colours/#256) has more information about them.
2526
* *Truecolor (16 million colors):* 24-bit color; 8 bits for each of red, green and blue. This is the standard that web pages and most monitors support. You may have seen these colors written as e.g. <span style="color:#9b4fd1">#9b4fd1</span>.
2627

2728
**The default color schemes in applications *must* be restricted to 12 colors: red, green, yellow, blue, magenta, cyan, and the bright versions of each of these.**
29+
2830
* While the wider palettes are useful for terminal theming controlled by the user, applications *must not* use them by default. The reason is that users may be using a variety of terminal themes with different backgrounds. **Truecolors and 8-bit colors will not render properly with all terminal themes.** Light-colored text will fade into a light background, and dark-colored text will fade into a dark background.
2931
* Most terminals allow you to configure these colors to whatever one pleases. In most themes, these 12 colors are set to contrast with the background.
3032
<tt><span style="color: #acacab; background-color:#050505">Themes with dark backgrounds <span style="color: #a9cdeb">set "blue" to be lighter</span></span></tt>,

src/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Some utilities require more expressive power in their configuration; for example
1313
## Configuration scopes
1414

1515
Depending on the application, the following scopes for a configuration are often seen in practice:
16+
1617
1. *Directory-scoped.* Applies to a directory and its subdirectories. Controlled by a file somewhere in this directory or a parent. For example, [`.gitignore`](https://git-scm.com/docs/gitignore) is directory-scoped.
1718
2. *Repository-scoped.* Applies to a repository: controlled by a file somewhere in a code repository. For example, [`clippy.toml`](https://github.com/rust-lang/rust-clippy#configuration) is repository-scoped.
1819
3. *User-scoped.* A file somewhere in the user's home directory.
@@ -21,16 +22,19 @@ Depending on the application, the following scopes for a configuration are often
2122
Not all applications support all of these: which scopes make sense is a matter of judgment and thinking about use cases. Some server-side applications support fetching configuration from a remote server; they are out of scope here.
2223

2324
**If applications support repository-scoped configuration:**
25+
2426
* Applications *should* put repository-scoped configuration in a `.config` directory under the repository root. Typically, applications place their configuration at the top level of the repository. However, too many config files at the top level can pollute directory listings.
2527
* Applications *should* allow both local and checked-in configuration files. For example, an application `myapp` should support configuration in both `.config/myapp.toml` and `.config/myapp.local.toml`. Entries in `./config/myapp.local.toml` *must* override those in `.config/myapp.toml`.
2628

2729
**If applications support user-scoped configuration:**
30+
2831
* On Unix platforms other than macOS, applications *should* follow the [XDG specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html).
2932
* On macOS and Windows, applications *should* either use `$HOME/.config` or the platform-native config directory. On macOS and Windows, the platform-native directories are somewhat harder to access on the command line, so `$HOME/.config` is a suitable alternative.
3033

3134
[dirs](https://crates.io/crates/dirs) is the most actively maintained Rust library for getting the native config directory (and other directories) for every platform.
3235

3336
**Applications *may* read configuration options over the command line and the environment.** It is often reasonable to let users override configuration via command-line options and environment variables. If so, then:
37+
3438
* Environment variables *must* be prefixed with a unique identifier based on the app. For example, an app called `myapp` can support a "limit" configuration through a `MYAPP_LIMIT` variable.
3539
* Environment variables *should* also be supported as command-line options. For example, `myapp --limit`. Command-line options are more discoverable than environment variables. If you actually *want* your options to be less discoverable, for example if exposing them would increase support load, you can add hidden command-line options.
3640
* Command-line arguments *must* override environment variables. An environment variable can be set further up in the environment. A command-line argument expresses user intent most directly.

src/handling-arguments.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ For a program that has subcommands, the following code structure is *recommended
77
```
88

99
Notes:
10+
1011
* **Only the top-level `App` is public.**
1112
* **`App` is a struct, one level above the command enum.**
1213
* While it is possible to make `App` an enum with all the subcommands, in my experience this design has always come back to bite me. This has always been because I've wanted to introduce global options later.

src/hierarchical-config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Hierarchical configuration
22

33
**Applications *should* follow a hierarchical configuration structure.** Use the following order, from highest priority to lowest.
4+
45
1. Command-line arguments
56
2. Environment variables
67
3. Directory or repository-scoped configuration

0 commit comments

Comments
 (0)