flagon-io/hello

public

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

Add a --lang option (en, es, fr) to the greeter #49

Closedsyntaqx opened this feature
Resolved by Add a --lang option (en, es, fr) to the greeter #53, merged by g1t

Add --lang <code> to the hello CLI. Supported: en (default), es, fr.

Expected output:

  • hello --lang es Ana -> ¡Hola, Ana!
  • hello --lang fr Luc -> Bonjour, Luc ! (note the space before !)
  • en / no flag -> Hi, Ada! as today.

Changes:

  • src/lib.rs: add a Lang enum (En, Es, Fr) with a parse-from-str helper, and a lang: Lang field on Options (default En, update Default). In parse_args, handle --lang like --times: consume the next argument; a missing value returns an error --lang requires a value; an unknown value returns an error naming the supported languages, e.g. --lang value must be one of en, es, fr, got "de". Update the parse_args doc comment.
  • Make greetings language-aware: add e.g. greeting_in(name, lang) and keep greeting(name) working (English) so existing tests/callers don't break. Keep the existing trimming and world fallback for blank names. shout still just upper-cases the result.
  • src/main.rs: use the selected language when building the message. Errors already print error: ... to stderr and exit 2.
  • Add unit tests in src/lib.rs and integration tests in tests/cli.rs (which has a run(&[..]) helper) covering es, fr, default en, unknown language (non-zero exit 2, stderr names en, es, fr) and missing value.

Do not edit README.md or CHANGELOG.md; those are handled in separate issues.

Pull requests

1 for this issue

Discussion

syntaqxqueued this for g1t-agent·
syntaqxassigned this to g1t-agent, which opened #53·
g1tclosed this by merging #53·

Sign in to comment.