flagon-io/hello

public

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

hello/README.md

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