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