File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 "github.com/spf13/cobra"
55
66 "github.com/devstream-io/devstream/internal/pkg/develop"
7+ "github.com/devstream-io/devstream/pkg/util/cli"
78 "github.com/devstream-io/devstream/pkg/util/log"
89)
910
1213 all bool
1314)
1415
16+ var validatePluginFlagNames = []string {
17+ "name" ,
18+ "all" ,
19+ }
20+
1521var developCMD = & cobra.Command {
1622 Use : "develop" ,
1723 Short : "Develop is used for develop a new plugin" ,
@@ -33,7 +39,8 @@ var developValidatePluginCMD = &cobra.Command{
3339Examples:
3440 dtm develop validate-plugin --name=YOUR-PLUGIN-NAME,
3541 dtm develop validate-plugin --all` ,
36- Run : developValidateCMDFunc ,
42+ Run : developValidateCMDFunc ,
43+ PreRun : cli .BindPFlags (validatePluginFlagNames ),
3744}
3845
3946func developCreateCMDFunc (cmd * cobra.Command , args []string ) {
Original file line number Diff line number Diff line change 1+ package cli
2+
3+ import (
4+ "log"
5+
6+ "github.com/spf13/cobra"
7+ "github.com/spf13/viper"
8+ )
9+
10+ type PreRunFunc func (cmd * cobra.Command , args []string )
11+
12+ // BindPFlags accepts a list of flag names and binds the corresponding flags to Viper. This function servers
13+ // as a workaround to a known bug in Viper, in which two commands can't share the same flag name.
14+ // To learn more about the bug, see: https://github.com/spf13/viper/issues/233
15+ func BindPFlags (flagNames []string ) PreRunFunc {
16+ return func (cmd * cobra.Command , args []string ) {
17+ for _ , name := range flagNames {
18+ if err := viper .BindPFlag (name , cmd .Flags ().Lookup (name )); err != nil {
19+ log .Fatalf ("Failed to bind flag %s: %s" , name , err )
20+ }
21+ }
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments