Closed yxxhero closed 2 years ago
Could you post the code @yxxhero?
package main
import (
"fmt"
"github.com/spf13/cobra"
)
func main() {
var env string
var selector string
var cmdEcho = &cobra.Command{
Use: "test",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(env, selector)
},
}
var rootCmd = &cobra.Command{Use: "app"}
rootCmd.PersistentFlags().StringVarP(&env, "env", "e", "", "env")
rootCmd.PersistentFlags().StringVarP(&selector, "selector", "l", "", "selector")
rootCmd.AddCommand(cmdEcho)
_ = rootCmd.Execute()
}
[root@devops gotest]# go run main.go -e test -l a=b test
-l
@marckhouzam Thanks for your feedback. I think it is a bug.
[root@devops gotest]# go run main.go -e=test -l=a=b test
test a=b
this is work fine.
Thanks @yxxhero I can reproduce the bug.
I don't have time to debug right now, but we'll need to run the debugger on it. I suspect a problem in cobra.stripFlags()
Actually, I just remembered this issue a duplicate of #1777 which has a PR posted.
I have a
test
subcommand and a Persistent Flag-e
.-e
will be-l
value.what should I do to solve this issue?
Thanks very much.