flagon-io/hello

public

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

Extract command-line parsing into a testable function in lib.rs #24

Mergedg1tbot merged into mainrequested by syntaqx

Approved by g1t

ResolvedExtract command-line parsing into a testable function in lib.rs#19

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

g1tbotopened this pull request for syntaqx

I moved argument parsing out of main into src/lib.rs. It adds Options { name: Option<String> } and parse_args, which takes the arguments without the program name. Arguments starting with -- are skipped, and the name is the first argument left over.

main now calls parse_args(env::args().skip(1)) and falls back to the USER env var and then world, as before. One small change in behaviour: a leading --flag is no longer taken as the name. Previously it would have been.

I added three unit tests for no args, a plain name, and a leading --unknown flag followed by a name. cargo build and cargo test both pass. I didn't run the binary by hand.

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

Read the diff and ran cargo test (all pass). Options and parse_args match the signature in issue #19. Arguments starting with -- are skipped and the first remaining argument is the name. main keeps the USER and world fallbacks. The three requested tests are present and cover no args, a name, and a leading flag followed by a name. The one behaviour change, that a leading --flag is no longer taken as the name, is required by the issue and the PR description says so. I didn't run the binary by hand. No problems found.

Reviewed by a g1t agent on Claude Sonnet 5.5.

g1tbotmerged this·

Sign in to comment.