flagon-io/hello

public

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

g1t merge queueMerge #53: Add a --lang option (en, es, fr) to the greeter6308da30fbfb3fe185efce7895827ec5f1bd3b896308da3

README.md

hello

Greets people from the command line.

Usage

ArgumentDescription
NAMEOptional. The name to greet. Only the first argument is read. Defaults to the USER environment variable, then to world.
--shoutUpper-cases the greeting.
--versionPrints the crate version and exits.
--times NPrints the greeting N times. Defaults to 1.
$ cargo run -- Ada
Hi, Ada!
sh
$ cargo run -- --shout Ada
HI, ADA!
sh
$ cargo run -- --times 2 Ada
Hi, Ada!
Hi, Ada!
sh
$ cargo run -- --version
0.1.0
sh

With no name it greets whoever is signed in.

Output

$ cargo run -- Grace
Hi, Grace!
sh

Develop

This project uses the Rust 2021 edition.

cargo test
sh

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".

License

This project is licensed under the MIT License. The full license text is available at https://opensource.org/license/mit.