hello/README.md

106 lines3,032 bytesCodeBlame
1# hello
2
3Greets people from the command line.
4
5## Usage
6
7| Argument | Description |
8| -------- | ----------- |
9| `NAME` | Optional. The name to greet. Only the first argument is read. Defaults to the `USER` environment variable, then to `world`. |
10| `--shout` | Upper-cases the greeting. |
11| `--whisper` | Lower-cases the greeting and ends it with `...` instead of `!`. With `--shout`, the last one given wins. |
12| `--version` | Prints the crate version and exits. |
13| `--times N` | Prints the greeting `N` times. Defaults to 1. |
14| `--lang LANG` | Greets in the given language. Supported values are `en`, `es` and `fr`. Defaults to `en`. |
15| `--loud`, `-L` | Ends the greeting with `!!!` instead of `!`. |
16| `--bye` | Prints `Goodbye, NAME!` after the greeting. |
17| `--wave` | Prints `o/` after the greeting. |
18| `--quiet` | Prints no greeting at all. `--version` still prints the version. |
19
20```sh
21$ cargo run -- Ada
22Hi, Ada!
23```
24
25```sh
26$ cargo run -- --shout Ada
27HI, ADA!
28```
29
30```sh
31$ cargo run -- --times 2 Ada
32Hi, Ada!
33Hi, Ada!
34```
35
36```sh
37$ cargo run -- --lang es Ana
38¡Hola, Ana!
39```
40
41```sh
42$ cargo run -- --lang fr Luc
43Bonjour, Luc !
44```
45
46```sh
47$ cargo run -- --version
480.1.0
49```
50
51With no arguments it greets whoever is signed in (the `USER` environment variable), or `world` if that is not set, and prints `Hi, NAME!`. Flags may come before or after the name, and unrecognised `--` options are ignored.
52
53## Examples
54
55```sh
56$ cargo run -- --shout --times 2 Ada
57HI, ADA!
58HI, ADA!
59```
60
61```sh
62$ cargo run -- --lang es --times 2 Ana
63¡Hola, Ana!
64¡Hola, Ana!
65```
66
67```sh
68$ cargo run -- --shout --lang fr Luc
69BONJOUR, LUC !
70```
71
72## Output
73
74```sh
75$ cargo run -- Grace
76Hi, Grace!
77```
78
79## Develop
80
81This project uses the Rust 2021 edition.
82
83```sh
84cargo test
85```
86
87Every pull request runs formatting, lints and tests.
88
89## Troubleshooting
90
91**`error: --times value must be a number, got "abc"`**
92
93`--times` needs a whole number of zero or more. If the value is anything else, such as `abc`, `-1` or `2.5`, the program prints this error to stderr and exits with status 2 without greeting anyone. Pass a plain number, for example `--times 3`. A `--times` with no value after it also fails, with `--times requires a value`.
94
95**The greeting says `Hi, world!` when I gave a name**
96
97An empty or whitespace-only name, such as `cargo run -- ""`, is treated as no name and the greeting uses `world`. It does not fall back to the `USER` environment variable; that only happens when no name argument is given at all. Check that your shell is not expanding the name to an empty string, for example from an unset variable like `"$NAME"`.
98
99**`error: --lang value must be one of en, es, fr, got "de"`**
100
101`--lang` only accepts `en`, `es` or `fr`. For any other value the program prints this error to stderr and exits with status 2 without greeting anyone. Pass one of the supported languages, for example `--lang es`.
102
103## License
104
105This project is licensed under the MIT License.
106The full license text is available at https://opensource.org/license/mit.