flagon-io/hello

public

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

Add a --times N flag that prints the greeting N times #27

Mergedg1tbot merged into mainrequested by syntaqx

Approved by g1t

ResolvedAdd a --times N flag that prints the greeting N times#22

Merged into main by g1t automatically, once it was ready, · b1c4249

g1tbotopened this pull request for syntaqx

I added a --times N flag that prints the greeting N times, one per line. It works together with --shout. cargo test passes, and cargo run -- --times 3 Ada prints Hello, Ada! three times.

  • Parsing: Options has a new times: usize field, defaulting to 1. --times takes the next argument as its value, so that value is never read as the name.
  • Errors: A missing or non-numeric value makes parse_args return an Err. main prints error: ... to stderr and exits with status 2.
  • API change: parse_args now returns Result<Options, String>, so I added .unwrap() to the existing parsing tests.
  • Default impl: Options now has a hand-written Default, because the derived one would have set times to 0.
  • Tests: The new unit tests cover the default, a valid value, a missing value and a non-number. The integration tests run --times 3 Ada and --times 2 --shout Ada. I also added one for a bad value, which checks for a non-zero exit and non-empty stderr.

I did not check how --times 0 behaves beyond the code: it prints nothing and exits successfully. I also did not check negative numbers, which fail to parse as usize and so are treated as errors.

syntaqxmarked this ready for review·
g1tbotrequested a review from g1t·
g1tbotapproved these changes

Read the diff and the surrounding code, and ran cargo test. All tests pass. The change matches issue #22. --times consumes the next argument, so the value is not mistaken for the name. A missing or non-numeric value returns Err. main prints error: ... to stderr and exits with status 2. The greeting prints times times and combines with --shout. The hand-written Default correctly keeps times at 1. I found no problems that block merging. Two behaviours you may want to know about: --times 0 prints nothing and exits 0, and a bad --times value is rejected even when --version is also given.

Reviewed by a g1t agent on Claude Sonnet 5.5.

g1tbotmerged this·

Sign in to comment.