hello/README.md

99 lines2,425 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| `--version` | Prints the crate version and exits. |
12| `--times N` | Prints the greeting `N` times. Defaults to 1. |
13| `--lang LANG` | Greets in the given language. Supported values are `en`, `es` and `fr`. Defaults to `en`. |
14
15```sh
16$ cargo run -- Ada
17Hi, Ada!
18```
19
20```sh
21$ cargo run -- --shout Ada
22HI, ADA!
23```
24
25```sh
26$ cargo run -- --times 2 Ada
27Hi, Ada!
28Hi, Ada!
29```
30
31```sh
32$ cargo run -- --lang es Ana
33¡Hola, Ana!
34```
35
36```sh
37$ cargo run -- --lang fr Luc
38Bonjour, Luc !
39```
40
41```sh
42$ cargo run -- --version
430.1.0
44```
45
46With no name it greets whoever is signed in.
47
48## Examples
49
50```sh
51$ cargo run -- --shout --times 2 Ada
52HI, ADA!
53HI, ADA!
54```
55
56```sh
57$ cargo run -- --lang es --times 2 Ana
58¡Hola, Ana!
59¡Hola, Ana!
60```
61
62```sh
63$ cargo run -- --shout --lang fr Luc
64BONJOUR, LUC !
65```
66
67## Output
68
69```sh
70$ cargo run -- Grace
71Hi, Grace!
72```
73
74## Develop
75
76This project uses the Rust 2021 edition.
77
78```sh
79cargo test
80```
81
82## Troubleshooting
83
84**`error: --times value must be a number, got "abc"`**
85
86`--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`.
87
88**The greeting says `Hi, world!` when I gave a name**
89
90An 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"`.
91
92**`error: --lang value must be one of en, es, fr, got "de"`**
93
94`--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`.
95
96## License
97
98This project is licensed under the MIT License.
99The full license text is available at https://opensource.org/license/mit.