diff --git a/internal/dependencymanager/add.go b/internal/dependencymanager/add.go index 40252f0d7..0270016b9 100644 --- a/internal/dependencymanager/add.go +++ b/internal/dependencymanager/add.go @@ -30,11 +30,13 @@ import ( ) type addFlagsCollection struct { - dependencyManagerFlagsCollection - name string `default:"" flag:"name" info:"Name of the dependency"` + *dependencyManagerFlagsCollection + name string } -var addFlags = addFlagsCollection{} +var addFlags = addFlagsCollection{ + dependencyManagerFlagsCollection: &dependencyManagerFlagsCollection{}, +} var addCommand = &command.Command{ Cmd: &cobra.Command{ @@ -43,8 +45,14 @@ var addCommand = &command.Command{ Example: "flow dependencies add testnet://0afe396ebc8eee65.FlowToken", Args: cobra.ExactArgs(1), }, - Flags: &addFlags, - RunS: add, + RunS: add, +} + +func init() { + // Add common flags. + addFlags.dependencyManagerFlagsCollection.AddToCommand(addCommand.Cmd) + // Add command-specific flags. + addCommand.Cmd.Flags().StringVar(&addFlags.name, "name", "", "Name of the dependency") } func add( @@ -58,7 +66,7 @@ func add( dep := args[0] - installer, err := NewDependencyInstaller(logger, state, addFlags.dependencyManagerFlagsCollection) + installer, err := NewDependencyInstaller(logger, state, *addFlags.dependencyManagerFlagsCollection) if err != nil { logger.Error(fmt.Sprintf("Error: %v", err)) return nil, err diff --git a/internal/dependencymanager/dependencyinstaller.go b/internal/dependencymanager/dependencyinstaller.go index 610709afd..cf0d6f412 100644 --- a/internal/dependencymanager/dependencyinstaller.go +++ b/internal/dependencymanager/dependencyinstaller.go @@ -26,6 +26,10 @@ import ( "os" "path/filepath" + "github.com/psiemens/sconfig" + + "github.com/spf13/cobra" + "github.com/onflow/flow-go/fvm/systemcontracts" flowGo "github.com/onflow/flow-go/model/flow" @@ -74,6 +78,17 @@ type dependencyManagerFlagsCollection struct { skipAlias bool `default:"false" flag:"skip-alias" info:"Skip prompting for an alias"` } +func (f *dependencyManagerFlagsCollection) AddToCommand(cmd *cobra.Command) { + err := sconfig.New(f). + FromEnvironment(util.EnvPrefix). + BindFlags(cmd.Flags()). + Parse() + + if err != nil { + panic(err) + } +} + type DependencyInstaller struct { Gateways map[string]gateway.Gateway Logger output.Logger