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 | | `--version` | Prints the crate version and exits. | |
| 12 | | `--times N` | Prints the greeting `N` times. Defaults to 1. | |
| 13 | |
| 14 | ```sh |
| 15 | $ cargo run -- Ada |
| 16 | Hello, Ada! |
| 17 | ``` |
| 18 | |
| 19 | ```sh |
| 20 | $ cargo run -- --shout Ada |
| 21 | HELLO, ADA! |
| 22 | ``` |
| 23 | |
| 24 | ```sh |
| 25 | $ cargo run -- --times 2 Ada |
| 26 | Hello, Ada! |
| 27 | Hello, Ada! |
| 28 | ``` |
| 29 | |
| 30 | ```sh |
| 31 | $ cargo run -- --version |
| 32 | 0.1.0 |
| 33 | ``` |
| 34 | |
| 35 | With no name it greets whoever is signed in. |
| 36 | |
| 37 | ## Output |
| 38 | |
| 39 | ```sh |
| 40 | $ cargo run -- Grace |
| 41 | Hello, Grace! |
| 42 | ``` |
| 43 | |
| 44 | ## Develop |
| 45 | |
| 46 | This project uses the Rust 2021 edition. |
| 47 | |
| 48 | ```sh |
| 49 | cargo test |
| 50 | ``` |
| 51 | |
| 52 | ## Troubleshooting |
| 53 | |
| 54 | **`error: --times value must be a number, got "abc"`** |
| 55 | |
| 56 | `--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`. |
| 57 | |
| 58 | **The greeting says `Hello, world!` when I gave a name** |
| 59 | |
| 60 | 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"`. |
| 61 | |
| 62 | ## License |
| 63 | |
| 64 | This project is licensed under the MIT License. |
| 65 | The full license text is available at https://opensource.org/license/mit. |