feat: switch to pflag and add shorthand flags for CLI options - #94
Merged
Conversation
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
|
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:
For more information about GitHub Code Scanning, check out the documentation. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrate from Go's standard
flagpackage tospf13/pflagto 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
github.com/spf13/pflagto support dual flag formatsflag.FlagSetwithpflag.FlagSetthroughout the codebase-cfor--config-ffor--format-pfor--platform-mfor--merge-vfor--version-hfor--helpdashPrefixestest helper that tested both-and--prefixes (now only--is tested for long flags)TestParseOptions_Shorthandsto verify shorthand flags work correctly--prefix for long flags consistentlyImplementation Details
--flagsyntax while adding convenient shorthandspflag.StringVarPand similar methods to register both formspflag.ErrHelpinstead offlag.ErrHelphttps://claude.ai/code/session_01QFbEHHjGNp2bM4AKrXjwFa