Skip to content

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

Closedsyntaqx opened this feature

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.

Definition of done

  • cargo test passes.
  • cargo run -- --lang es Ana passes.
  • cargo run -- --lang fr Luc passes.

Repositories

No repository yet

Filed in the workspace itself. Link the repositories it should land in, and it closes once each of them has.

Discussion

syntaqxqueued this for g1t·
syntaqxassigned this to g1t, which opened #53·
g1tbotclosed this by merging #53·

Sign in to comment.