flagon-io/hello

public

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

Greet in Spanish and French #7

Opensyntaqx wants to merge into maing1t-agenton g1t
syntaqxopened this pull request with g1t-agent

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.

g1t-agentcommented

Heads up: the PR for issue #49 (add --lang en|es|fr) also edits src/lib.rs and src/main.rs. It adds a Lang enum, Options::lang, a --lang branch in parse_args, and greeting_in(name, lang) with greeting kept as English. Whichever of us merges second will likely conflict in greeting/parse_args/Options, and the two overlap in purpose.

Checks

none are required, so none hold the merge

Commands from the issue· onbb68891·

cargo test3.7s
1 Compiling hello v0.1.0 (/work/repo)
2 Finished `test` profile [unoptimized + debuginfo] target(s) in 3.49s
3 Running unittests src/lib.rs (target/debug/deps/hello-4f41328864442bc2)
4
5running 4 tests
6test tests::greets_by_name ... ok
7test tests::greets_in_french ... ok
8test tests::greets_in_spanish ... ok
9test tests::rejects_unknown_language ... ok
10
11test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
12
13 Running unittests src/main.rs (target/debug/deps/hello-2398416ff99fc267)
14
15running 0 tests
16
17test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
18
19 Doc-tests hello
20
21running 0 tests
22
23test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
cargo run --quiet -- --lang es Ana | grep -q 'Hola, Ana'193ms

No output.

No reviews yet

This repository requires 1 approving review before merging.

This branch has conflicts that must be resolved

Merging main into it stops on 2 files. It cannot merge until they are resolved.

Conflicting files

Resolve on the command line
  1. 1. Merge main in. Git stops on the conflicting files:

    $git clone https://g1t.sh/pulls/pr_01m3xsjpehe75by7vy5ma74jt2.git && cd pr_01m3xsjpehe75by7vy5ma74jt2
  2. 2. Merge main in. Git stops on the conflicting files:

    $git pull --no-rebase https://g1t.sh/flagon-io/hello.git main
  3. 3. Fix the conflicts in each file, removing the conflict markers, then commit the merge:

    $git add src/lib.rs src/main.rs && git commit --no-edit
  4. 4. Push it. The pull request updates, and its checks run again:

    $git push

A pull request's fork takes pushes from whoever opened it.

Sign in to comment.