expose ValidateRequiredFlags and ValidateFlagGroups#1760
Merged
marckhouzam merged 1 commit intospf13:mainfrom Sep 27, 2022
jinlohwu:main
Merged
expose ValidateRequiredFlags and ValidateFlagGroups#1760marckhouzam merged 1 commit intospf13:mainfrom jinlohwu:main
marckhouzam merged 1 commit intospf13:mainfrom
jinlohwu:main
Conversation
|
The Cobra project currently lacks enough contributors to adequately respond to all PRs. This bot triages issues and PRs according to the following rules:
|
Contributor
Author
|
Hi, exposing these two functions is more convenient and does not conflict with other parts. I have changed it in my local workspace, it works well. |
marckhouzam
reviewed
Sep 23, 2022
Collaborator
|
This seems reasonable to give users more flexibility in handling flags. |
marckhouzam
reviewed
Sep 26, 2022
Closed
Contributor
Author
|
@marckhouzam thx for reviewing and helping to merge the code. |
jimschubert
added a commit
to jimschubert/cobra
that referenced
this pull request
Oct 3, 2022
* main: (39 commits) Add '--version' flag to Help output (spf13#1707) Expose ValidateRequiredFlags and ValidateFlagGroups (spf13#1760) Document option to hide the default completion cmd (spf13#1779) ci: add workflow_dispatch (spf13#1387) add missing license headers (spf13#1809) ci: use action/setup-go's cache (spf13#1783) Adjustments to documentation (spf13#1656) Rename Powershell completion tests (spf13#1803) Support for case-insensitive command names (spf13#1802) Deprecate ExactValidArgs() and test combinations of args validators (spf13#1643) Use correct stale action `exempt-` yaml keys (spf13#1800) With go 1.18, we must use go install for a binary (spf13#1726) Clarify SetContext documentation (spf13#1748) ci: test on Golang 1.19 (spf13#1782) fix: show flags that shadow parent persistent flag in child help (spf13#1776) Update gopkg.in/yaml.v2 to gopkg.in/yaml.v3 (spf13#1766) fix(bash-v2): activeHelp length check syntax (spf13#1762) fix: correct command path in see_also for YAML doc (spf13#1771) build(deps): bump github.com/inconshreveable/mousetrap (spf13#1774) docs: add zitadel to the list (spf13#1772) ...
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.
Hi, dear reviewers,
In my project, there is one complex command with a lot of flags, we need to set part of them as required, and other flags are optional, all optional flags were defined from an API server. I have implemented this feature to add dynamic flags in issue #1758.
as talked with @marckhouzam in the last issue, it looks like my method is on the right way.
In the next work, I add some flags in
init()function and callMarkFlagRequiredto mark them as required flags. but, because I have setDisableFlagParsingastrue, and need to callfunc (c *Command) ParseFlags(args []string) errorto parse all flags manually, the function which validates the required flag will not be called.for now, I have to set up a map and store all required flags, then check if exist in arguments one bye one before
ParseFlags(). It works but looks not graceful.I went through the source code of Cobra, and it looks like I need to call
validateRequiredFlags()andvalidateFlagGroups()manually afterParseFlags(args []string), and functionvalidateRequiredFlags()was called byExecute(), so I created this PR to expose these two functions.Thx for reviewing this PR.
B&R,
Skeet