flagon-io/hello

public

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

hello/README.md

80 lines2,207 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## Output
49
50```sh
51$ cargo run -- Grace
52Hi, Grace!
53```
54
55## Develop
56
57This project uses the Rust 2021 edition.
58
59```sh
60cargo test
61```
62
63## Troubleshooting
64
65**`error: --times value must be a number, got "abc"`**
66
67`--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`.
68
69**The greeting says `Hi, world!` when I gave a name**
70
71An 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"`.
72
73**`error: --lang value must be one of en, es, fr, got "de"`**
74
75`--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`.
76
77## License
78
79This project is licensed under the MIT License.
80The full license text is available at https://opensource.org/license/mit.