flagon-io/hello

public

Greets people from the command line. The sample repository for g1t.

hello/README.md

103 lines2,855 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| `--loud`, `-L` | Ends the greeting with `!!!` instead of `!`. |
15| `--bye` | Prints `Goodbye, NAME!` after the greeting. |
16| `--wave` | Prints `o/` after the greeting. |
17| `--quiet` | Prints no greeting at all. `--version` still prints the version. |
18
19```sh
20$ cargo run -- Ada
21Hi, Ada!
22```
23
24```sh
25$ cargo run -- --shout Ada
26HI, ADA!
27```
28
29```sh
30$ cargo run -- --times 2 Ada
31Hi, Ada!
32Hi, Ada!
33```
34
35```sh
36$ cargo run -- --lang es Ana
37¡Hola, Ana!
38```
39
40```sh
41$ cargo run -- --lang fr Luc
42Bonjour, Luc !
43```
44
45```sh
46$ cargo run -- --version
470.1.0
48```
49
50With 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.
51
52## Examples
53
54```sh
55$ cargo run -- --shout --times 2 Ada
56HI, ADA!
57HI, ADA!
58```
59
60```sh
61$ cargo run -- --lang es --times 2 Ana
62¡Hola, Ana!
63¡Hola, Ana!
64```
65
66```sh
67$ cargo run -- --shout --lang fr Luc
68BONJOUR, LUC !
69```
70
71## Output
72
73```sh
74$ cargo run -- Grace
75Hi, Grace!
76```
77
78## Develop
79
80This project uses the Rust 2021 edition.
81
82```sh
83cargo test
84```
85
86## Troubleshooting
87
88**`error: --times value must be a number, got "abc"`**
89
90`--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`.
91
92**The greeting says `Hi, world!` when I gave a name**
93
94An 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"`.
95
96**`error: --lang value must be one of en, es, fr, got "de"`**
97
98`--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`.
99
100## License
101
102This project is licensed under the MIT License.
103The full license text is available at https://opensource.org/license/mit.