Skip to content

Commit

Permalink
Fix embedded flags issue when running Dependency Manager flags manual…
Browse files Browse the repository at this point in the history
…ly (#1530)

* Fix embedded flags issue

* Run lint fix

* Use sconfig

* Run goimport fix

---------

Co-authored-by: Chase Fleming <[email protected]>
  • Loading branch information
chasefleming and chasefleming authored Apr 22, 2024
1 parent 57889d4 commit a42acab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/dependencymanager/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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(
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions internal/dependencymanager/dependencyinstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a42acab

Please sign in to comment.