README.md
hello
Greets people from the command line.
Usage
| Argument | Description |
|---|---|
NAME | Optional. The name to greet. Only the first argument is read. Defaults to the USER environment variable, then to world. |
--shout | Upper-cases the greeting. |
--version | Prints the crate version and exits. |
--times N | Prints the greeting N times. Defaults to 1. |
--lang LANG | Greets in the given language. Supported values are en, es and fr. Defaults to en. |
--loud, -L | Ends the greeting with !!! instead of !. |
--bye | Prints Goodbye, NAME! after the greeting. |
--wave | Prints o/ after the greeting. |
--quiet | Prints no greeting at all. --version still prints the version. |
$ cargo run -- Ada
Hi, Ada!$ cargo run -- --shout Ada
HI, ADA!$ cargo run -- --times 2 Ada
Hi, Ada!
Hi, Ada!$ cargo run -- --lang es Ana
¡Hola, Ana!$ cargo run -- --lang fr Luc
Bonjour, Luc !$ cargo run -- --version
0.1.0With 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.
Examples
$ cargo run -- --shout --times 2 Ada
HI, ADA!
HI, ADA!$ cargo run -- --lang es --times 2 Ana
¡Hola, Ana!
¡Hola, Ana!$ cargo run -- --shout --lang fr Luc
BONJOUR, LUC !Output
$ cargo run -- Grace
Hi, Grace!Develop
This project uses the Rust 2021 edition.
cargo testEvery pull request runs formatting, lints and tests.
Troubleshooting
error: --times value must be a number, got "abc"
--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.
The greeting says Hi, world! when I gave a name
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".
error: --lang value must be one of en, es, fr, got "de"
--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.
License
This project is licensed under the MIT License. The full license text is available at https://opensource.org/license/mit.