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 alangparameter (default behavior is no longer embedded) - Changed return type from
StringtoOption<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
--langoption 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
USERenvironment variable or"world"
Key features:
- ✅
hello --lang es Anaoutputs¡Hola, Ana! - ✅
hello --lang fr LucoutputsBonjour, Luc ! - ✅
hello Alicedefaults 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.rsfor easy testing