Parse invocation flags across command discovery
This commit is contained in:
@@ -77,7 +77,7 @@ func (session *Session) Parse(argv []string) commandmeta.Result {
|
||||
}
|
||||
|
||||
remaining := append(commandpath.CloneTokens(unconsumed), tail...)
|
||||
localFlags := commandmeta.EffectiveFlags(selectedNode.Flags, selectedNode.CoreFlags)
|
||||
localFlags := commandmeta.EffectiveFlags(append(append([]commandmeta.Flag(nil), selectedNode.Flags...), selectedNode.InvocationFlags...), selectedNode.CoreFlags)
|
||||
aliases := session.flagAliases
|
||||
if session.flagAliasesForPath != nil {
|
||||
aliases = session.flagAliasesForPath(result.Path)
|
||||
@@ -115,6 +115,15 @@ func (session *Session) Parse(argv []string) commandmeta.Result {
|
||||
result.FlagSpellings[index] = raw.spellingsCopy()
|
||||
}
|
||||
}
|
||||
result.InvocationFlagValues = make([][]string, len(selectedNode.InvocationFlags))
|
||||
result.InvocationFlagSpellings = make([][]string, len(selectedNode.InvocationFlags))
|
||||
for index, flag := range selectedNode.InvocationFlags {
|
||||
if value := selected.Flags().Lookup(flag.Name); value != nil {
|
||||
raw := value.Value.(*rawValue)
|
||||
result.InvocationFlagValues[index] = raw.valuesCopy()
|
||||
result.InvocationFlagSpellings[index] = raw.spellingsCopy()
|
||||
}
|
||||
}
|
||||
if helpFlag := selected.Flags().Lookup("help"); helpFlag != nil {
|
||||
helpRequested, err := helpFlag.Value.(*rawValue).lastBool()
|
||||
if err != nil {
|
||||
@@ -271,7 +280,7 @@ func (session *Session) UsageLine(path []string) (string, *commandmeta.Failure)
|
||||
if flag.Name != "debug" || !flag.Boolean {
|
||||
continue
|
||||
}
|
||||
for _, effective := range commandmeta.EffectiveFlags(declaration.Flags, declaration.CoreFlags) {
|
||||
for _, effective := range commandmeta.EffectiveFlags(append(append([]commandmeta.Flag(nil), declaration.Flags...), declaration.InvocationFlags...), declaration.CoreFlags) {
|
||||
if effective.Name == "debug" {
|
||||
spelling := "--debug"
|
||||
if effective.Short != "" {
|
||||
@@ -330,7 +339,7 @@ func buildTree(root *commandmeta.Command) (*spfcobra.Command, map[*spfcobra.Comm
|
||||
helpFlag := backend.Flags().Lookup("help")
|
||||
helpFlag.NoOptDefVal = "true"
|
||||
helpFlag.Usage = "help for this command (default: false)"
|
||||
for _, declarationFlag := range commandmeta.EffectiveFlags(declaration.Flags, declaration.CoreFlags) {
|
||||
for _, declarationFlag := range commandmeta.EffectiveFlags(append(append([]commandmeta.Flag(nil), declaration.Flags...), declaration.InvocationFlags...), declaration.CoreFlags) {
|
||||
value := &rawValue{boolean: declarationFlag.Boolean}
|
||||
backend.Flags().VarP(value, declarationFlag.Name, declarationFlag.Short, flagUsage(declarationFlag))
|
||||
backendFlag := backend.Flags().Lookup(declarationFlag.Name)
|
||||
|
||||
Reference in New Issue
Block a user