Skip to content

docs: clarify SortFlags example with complete runnable program#488

Merged
tomasaschan merged 1 commit into
spf13:masterfrom
happysnaker:docs-sortflags-example
Jul 3, 2026
Merged

docs: clarify SortFlags example with complete runnable program#488
tomasaschan merged 1 commit into
spf13:masterfrom
happysnaker:docs-sortflags-example

Conversation

@happysnaker

Copy link
Copy Markdown

Summary

Fixes #456

The existing SortFlags example used flags.SortFlags without showing that SortFlags is a field on FlagSet, not a package-level variable. This led to confusion for users who tried to use pflag.SortFlags directly (pflag.SortFlags does not exist).

Changes

  • Updated the example to show a complete, runnable program using NewFlagSet
  • Added a separate note for the CommandLine case: pflag.CommandLine.SortFlags = false
  • Added proper imports and main() function

The existing SortFlags example used 'flags.SortFlags' without showing
that SortFlags is a field on FlagSet, not a package-level variable.
This led to confusion for users who tried to use pflag.SortFlags
directly.

Updated the example to show a complete program using NewFlagSet,
and added a separate note for the CommandLine case.

Fixes spf13#456

@tomasaschan tomasaschan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@tomasaschan tomasaschan merged commit dca783a into spf13:master Jul 3, 2026
8 checks passed
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.

.SortFlags documentation could be improved

2 participants