Skip to content

feat: switch to pflag and add shorthand flags for CLI options - #94

Merged
nozaq merged 3 commits into
mainfrom
claude/migrate-to-pflag-lqcea4
Aug 2, 2026
Merged

feat: switch to pflag and add shorthand flags for CLI options#94
nozaq merged 3 commits into
mainfrom
claude/migrate-to-pflag-lqcea4

Conversation

@nozaq

@nozaq nozaq commented Aug 2, 2026

Copy link
Copy Markdown
Member

Summary

Migrate from Go's standard flag package to spf13/pflag to support both long-form (--flag) and shorthand (-f) command-line flags. This improves CLI usability by providing concise alternatives for frequently-used options.

Key Changes

  • Dependency: Added github.com/spf13/pflag to support dual flag formats
  • Flag migration: Replaced flag.FlagSet with pflag.FlagSet throughout the codebase
  • Shorthand flags added:
    • -c for --config
    • -f for --format
    • -p for --platform
    • -m for --merge
    • -v for --version
    • -h for --help
  • Documentation: Updated all references in docs, comments, and test fixtures to reflect the new flag format
  • Test updates:
    • Removed the dashPrefixes test helper that tested both - and -- prefixes (now only -- is tested for long flags)
    • Added TestParseOptions_Shorthands to verify shorthand flags work correctly
    • Updated all test cases to use -- prefix for long flags consistently

Implementation Details

  • The migration maintains backward compatibility with existing --flag syntax while adding convenient shorthands
  • All CLI flag parsing now goes through pflag.StringVarP and similar methods to register both forms
  • Error handling updated to check pflag.ErrHelp instead of flag.ErrHelp
  • Test coverage expanded to explicitly verify shorthand flag behavior

https://claude.ai/code/session_01QFbEHHjGNp2bM4AKrXjwFa

Replace the standard library's flag package with github.com/spf13/pflag, so
decolint follows the GNU convention its users expect from other linters:
--long flags plus shorthands for the ones typed most often (-c/--config,
-f/--format, -p/--platform, -m/--merge, -v/--version, -h/--help).

BREAKING CHANGE: single-dash long flags are gone. `decolint -format=github`
must now be spelled `decolint --format=github`; the old spelling fails with
exit code 2.

pflag was already in the module graph, and cmd/dockerflagsgen already imported
it, so this adds no dependency to the build. cmd/dockerflagsgen's -o moves
along with it; cmd/docgen's -update stays on flag because `go test` owns that
flag set.

Unlike flag, pflag's ContinueOnError reports nothing on a parse error, so
parseOptions prints the usage text itself to keep decolint's output as it was.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QFbEHHjGNp2bM4AKrXjwFa
@nozaq nozaq changed the title Switch to pflag and add shorthand flags for CLI options feat: switch to pflag and add shorthand flags for CLI options Aug 2, 2026
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

claude added 2 commits August 2, 2026 09:16
Also fix two "---platform" typos left by the flag renaming.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QFbEHHjGNp2bM4AKrXjwFa
pflag returns a parse error rather than writing it to the flag set's output,
so parseOptions writes only the usage text there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QFbEHHjGNp2bM4AKrXjwFa
@nozaq
nozaq merged commit 427c385 into main Aug 2, 2026
14 checks passed
@nozaq
nozaq deleted the claude/migrate-to-pflag-lqcea4 branch August 2, 2026 09:21
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.

3 participants