Skip to content

Conversation

@pohly
Copy link

@pohly pohly commented Sep 15, 2021

This is useful for programs which want to define some flags with pflag (for
example, in external packages) but still need to use Go flag command line
parsing to preserve backward compatibility with previous releases.

Without this in pflag, such tools have to resort to copying via the public
API, which leads to less useful help messages (type of basic values
will be unknown).

Fixes: #329

@CLAassistant
Copy link

CLAassistant commented Sep 15, 2021

CLA assistant check
All committers have signed the CLA.

@pohly pohly force-pushed the copy-to-go-flagset branch from d350035 to 7849f50 Compare October 4, 2021 15:45
@pohly pohly changed the title WIP: implement CopyToGoFlagSet implement CopyToGoFlagSet Oct 4, 2021
usage += " (DEPRECATED: " + flag.Deprecated + ")"
}

switch value := flag.Value.(type) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks a bit fragile; how do we ensure it keeps working when new value types are added to the project (as has been done a few times since this PR was opened, e.g. #348, and will probably be done again, e.g. #359)? Is there a better way to register these things with flag without having to know the exact type of the thing?

Copy link
Author

Choose a reason for hiding this comment

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

This list only needs to include types which have a counterpart in the standard flag package. Everything else is handled through the generic default case. In other words, the list is complete until the standard package gets extended, and even then it's not breaking.

@pohly
Copy link
Author

pohly commented Jul 17, 2025

I'll resolve the merge conflict soonish... a bit busy right now (Kubernetes code freeze is looming). 😅

Thanks for taking a look at pflag and checking issues/PRs!

@pohly pohly force-pushed the copy-to-go-flagset branch from 7849f50 to 1de06c0 Compare July 30, 2025 08:26
This is useful for programs which want to define some flags with pflag (for
example, in external packages) but still need to use Go flag command line
parsing to preserve backward compatibility with previous releases, in
particular support for single-dash flags.

Without this in pflag, such tools have to resort to copying via the public
API, which leads to less useful help messages (type of basic values
will be unknown).
@pohly pohly force-pushed the copy-to-go-flagset branch from 1de06c0 to 44aa4aa Compare July 30, 2025 08:27
@pohly
Copy link
Author

pohly commented Jul 30, 2025

I rebased (conflict with other new method added at the same place, so easy to resolve), please merge now.

@tomasaschan tomasaschan merged commit 1db553c into spf13:master Aug 2, 2025
5 checks passed
@pohly
Copy link
Author

pohly commented Aug 18, 2025

I know I missed 1.0.7 (sorry for the delay!), but perhaps a 1.0.8 can follow soon? 🙏

@tomasaschan tomasaschan added this to the 1.0.x milestone Aug 18, 2025
@tomasaschan
Copy link
Collaborator

Yeah, I don't see why not. Only caveat is that while I'm on parental leave (until Feb next year) my mental space to sit down and do proper work on this project (or anything, really 😅) is sporadic and irregular, so I'm not going to make any promises on a timeline.

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.

support traditional single-dash flags

3 participants