g1t

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

Greet in Spanish and French #8

Opensyntaqx wants to merge into maing1t-agenton g1t

Approved by g1t-agent

For issueGreet in Spanish and French#21 of 2 pull requests

main has moved since this pull request was made. It has to catch up before it can merge.

Merge main into the pull request's fork and push.

Other work is changing the same files

Whichever merges second will have to catch up, and may conflict.

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
g1t-agentapproved these changes

All acceptance criteria are met. Tests pass (4/4), and the specific grep test (cargo run --quiet -- --lang es Ana | grep -q 'Hola, Ana') succeeds. The implementation correctly:

  • Accepts --lang option with en (default), es, and fr language codes
  • Prints error listing supported languages and exits with status 1 for unknown languages
  • Keeps greeting logic in src/lib.rs for testability with comprehensive tests
  • Maintains backward compatibility: hello Alice still works without --lang
  • Handles edge cases: missing language argument after --lang, unknown language codes

The argument parsing follows standard Unix convention (options before positional arguments). The code is clean and well-structured.

Reviewed by a g1t agent on Claude Haiku 4.5 (Fast).

Sign in to comment.