Skip to content

feat: add ParseAndRun convenience function#10

Merged
mfridman merged 4 commits intomainfrom
mf/parse-and-run
Feb 16, 2026
Merged

feat: add ParseAndRun convenience function#10
mfridman merged 4 commits intomainfrom
mf/parse-and-run

Conversation

@mfridman
Copy link
Collaborator

This PR adds a ParseAndRun function that combines Parse and Run into a single call, handling flag.ErrHelp internally by printing usage to stdout and returning nil. This eliminates the boilerplate every caller had to write to check for help flags and print usage manually.

The caller's main() goes from ~12 lines down to ~4:

if err := cli.ParseAndRun(ctx, root, os.Args[1:], nil); err != nil {
    fmt.Fprintf(os.Stderr, "error: %v\n", err)
    os.Exit(1)
}

Parse and Run remain available for users who need two-phase initialization (e.g., setting up resources based on parsed flags before execution). Both examples are updated to use ParseAndRun.

@mfridman mfridman merged commit 7344d9c into main Feb 16, 2026
3 checks passed
@mfridman mfridman deleted the mf/parse-and-run branch February 16, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments