g1t

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

Greet in Spanish and French #2

Opensyntaqx opened this feature

Add a --lang option taking en (the default), es or fr:

$ hello --lang es Ana
¡Hola, Ana!
$ hello --lang fr Luc
Bonjour, Luc !

An unknown language should print an error naming the languages that are supported and exit with a non-zero status. Keep the greeting logic in src/lib.rs so it can be tested.

Pull requests

2 for this issue, none merged

  1. Greet in Spanish and French #73 files+56−15Checks passedbb68891

    Ready for review·g1t-agenton g1t· opened by syntaqx

    I added a --lang option that takes en (the default), es or fr. cargo test passes, and the --lang es Ana | grep check passes. I didn't check the French output by hand; the new unit test covers it. src/lib.rs: greeting(name, lang) now returns Result<String, String>. It produces Hello, {name}!, ¡Hola, {name}! or Bonjour, {name} !. The French greeting has a space before the !, as in the issue. An unknown language returns an error naming the supported ones, from a new LANGUAGES constant. There are new unit tests for each language and for the error case. src/main.rs: it parses --lang <code> and --lang=<code>, and the name stays a positional argument. An unknown language prints error: unsupported language 'de' (supported: en, es, fr) to stderr and exits with status 2. A --lang with no value also exits with status 2. README.md: I added a short usage example for --lang. greeting now takes a second argument, so any other caller of it needs updating. Within this repo only main.rs calls it.

  2. Greet in Spanish and French #83 files+66−8Checks passed4b4b992

    Ready for review·g1t-agenton g1t· opened by syntaqx

    Summary I've successfully implemented multi-language support for the greeting application. Here's what changed: In src/lib.rs: Modified the greeting() function to accept a lang parameter (default behavior is no longer embedded) Changed return type from String to Option<String> to gracefully handle unsupported languages Added support for English (en), Spanish (es), and French (fr) Added tests for each language and for handling unknown languages In src/main.rs: Added --lang option parsing that accepts language codes before the name argument When an unknown language is specified, the program prints an error message listing supported languages and exits with status 1 Maintained backward compatibility: the name argument is still optional and defaults to the USER environment variable or "world" Key features: ✅ hello --lang es Ana outputs ¡Hola, Ana! ✅ hello --lang fr Luc outputs Bonjour, Luc ! ✅ hello Alice defaults to English: Hello, Alice! ✅ Unknown languages print an error with supported options and exit with code 1 ✅ All tests pass, including the specific grep test from the issue ✅ Greeting logic is kept in lib.rs for easy testing

Discussion

Sign in to comment.