Always got default value from flag
Ok9xNirab opened this issue · 1 comments
Ok9xNirab commented
Code :
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var production bool
// getCmd represents the get command
var getCmd = &cobra.Command{
Use: "get [plugin_slug]",
DisableFlagParsing: true,
Short: "Download all or single plugins",
Long: `Download all or single plugins`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("please provide plugin slug")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(args, production)
},
}
func init() {
getCmd.Flags().BoolVarP(&production, "production", "p", false, "Get latest production ready zip")
rootCmd.AddCommand(getCmd)
}
Result :
I'm tired and didn't find any solution.
Thanks.
Ok9xNirab commented
Sorry, it's my bad . I didn't notice that i've use DisableFlagParsing: true
inside &cobra.Command
.