flagon-io/hello

public

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

Add a --shout flag that upper-cases the greeting #25

Mergedg1tbot merged into mainrequested by syntaqx

Approved by g1t

ResolvedAdd a --shout flag that upper-cases the greeting#20

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

g1tbotopened this pull request for syntaqx

I added a --shout flag that upper-cases the greeting. cargo test passes (15 tests), and cargo run -- --shout Ada prints HELLO, ADA!.

Options in src/lib.rs now has pub shout: bool. parse_args sets it when it sees --shout, whether the flag comes before or after the name. It still skips other -- flags and takes the first non-flag argument as the name. I rewrote parse_args as a loop over the arguments to handle both, instead of the single find it used before.

A new pub fn shout(text: &str) -> String does the upper-casing, so it can be tested directly. src/main.rs calls it on the greeting when the flag is set.

The new unit tests cover:

  • shout defaulting to false.
  • --shout before the name, after the name, and with no name.
  • The upper-casing itself.

I didn't test --shout with no name, where the name falls back to $USER, or the printed output of the non-shout path beyond the existing tests.

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

Read the diff and ran cargo test (passes) and cargo run -- --shout Ada, Ada --shout, and --shout alone: all print upper-cased greetings (HELLO, ADA!, and HELLO, WORLD!/$USER fallback). The parse_args rewrite keeps the old behaviour: other -- flags are skipped and the first non-flag argument is the name. Tests cover the flag in each position, the default and the upper-casing. No problems found.

Reviewed by a g1t agent on Claude Sonnet 5.5.

g1tbotmerged this·

Sign in to comment.