Skip to content

Commit

Permalink
fix(cmd): fix wrong app path for migrations (#3572)
Browse files Browse the repository at this point in the history
* fix wrong app path for migrations

* group the commands for c.AddCommand

---------

Co-authored-by: Pantani <Pantani>
  • Loading branch information
Pantani authored Jul 19, 2023
1 parent b906822 commit 3c6c598
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 80 deletions.
14 changes: 8 additions & 6 deletions ignite/cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ chain.
c.PersistentFlags().AddFlagSet(flagSetKeyringBackend())
c.PersistentFlags().AddFlagSet(flagSetKeyringDir())

c.AddCommand(NewAccountCreate())
c.AddCommand(NewAccountDelete())
c.AddCommand(NewAccountShow())
c.AddCommand(NewAccountList())
c.AddCommand(NewAccountImport())
c.AddCommand(NewAccountExport())
c.AddCommand(
NewAccountCreate(),
NewAccountDelete(),
NewAccountShow(),
NewAccountList(),
NewAccountImport(),
NewAccountExport(),
)

return c
}
Expand Down
75 changes: 39 additions & 36 deletions ignite/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,31 @@ func preRunHandler(cmd *cobra.Command, _ []string) error {
session := cliui.New()
defer session.End()

if err := configMigrationPreRunHandler(cmd, session); err != nil {
path := flagGetPath(cmd)
path, err := filepath.Abs(path)
if err != nil {
return err
}

if err := toolsMigrationPreRunHandler(cmd, session); err != nil {
_, appPath, err := gomodulepath.Find(path)
if err != nil {
return err
}

return bufMigrationPreRunHandler(cmd, session)
}

func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) error {
session.StartSpinner("Checking missing tools...")

path := flagGetPath(cmd)
path, err := filepath.Abs(path)
if err != nil {
if err := configMigrationPreRunHandler(cmd, session, appPath); err != nil {
return err
}

_, appPath, err := gomodulepath.Find(path)
if err != nil {
if err := toolsMigrationPreRunHandler(cmd, session, appPath); err != nil {
return err
}

return bufMigrationPreRunHandler(cmd, session, appPath)
}

func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath string) error {
session.StartSpinner("Checking missing tools...")

toolsFilename := filepath.Join(appPath, doctor.ToolsFile)
if _, err := os.Stat(toolsFilename); os.IsNotExist(err) {
return errors.New("the dependency tools file is missing, run `ignite doctor` and try again")
Expand All @@ -152,25 +152,27 @@ func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) err
unused := cosmosgen.UnusedTools(f)

session.StopSpinner()
if len(missing) > 0 {
question := fmt.Sprintf(
msgMigrationAddTools,
toolsFilename,
strings.Join(missing, ", "),
)
if err := session.AskConfirm(question); err != nil {
missing = []string{}
if !getYes(cmd) {
if len(missing) > 0 {
question := fmt.Sprintf(
msgMigrationAddTools,
toolsFilename,
strings.Join(missing, ", "),
)
if err := session.AskConfirm(question); err != nil {
missing = []string{}
}
}
}

if len(unused) > 0 {
question := fmt.Sprintf(
msgMigrationRemoveTools,
toolsFilename,
strings.Join(unused, ", "),
)
if err := session.AskConfirm(question); err != nil {
unused = []string{}
if len(unused) > 0 {
question := fmt.Sprintf(
msgMigrationRemoveTools,
toolsFilename,
strings.Join(unused, ", "),
)
if err := session.AskConfirm(question); err != nil {
unused = []string{}
}
}
}
if len(missing) == 0 && len(unused) == 0 {
Expand All @@ -186,14 +188,16 @@ func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) err
return os.WriteFile(toolsFilename, buf.Bytes(), 0o644)
}

func bufMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) error {
appPath := flagGetPath(cmd)
func bufMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath string) error {
hasFiles := chain.CheckBufFiles(appPath)
if hasFiles {
return nil
}
if err := session.AskConfirm(msgMigrationBuf); err != nil {
return ErrProtocUnsupported

if !getYes(cmd) {
if err := session.AskConfirm(msgMigrationBuf); err != nil {
return ErrProtocUnsupported
}
}

sm, err := chain.BoxBufFiles(appPath)
Expand All @@ -207,8 +211,7 @@ func bufMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) error
return nil
}

func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session) (err error) {
appPath := flagGetPath(cmd)
func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath string) (err error) {
configPath := getConfig(cmd)
if configPath == "" {
if configPath, err = chainconfig.LocateDefault(appPath); err != nil {
Expand Down
24 changes: 13 additions & 11 deletions ignite/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ To get started, create a blockchain:
},
}

c.AddCommand(NewScaffold())
c.AddCommand(NewChain())
c.AddCommand(NewGenerate())
c.AddCommand(NewNode())
c.AddCommand(NewAccount())
c.AddCommand(NewRelayer())
c.AddCommand(NewTools())
c.AddCommand(NewDocs())
c.AddCommand(NewVersion())
c.AddCommand(NewPlugin())
c.AddCommand(NewDoctor())
c.AddCommand(
NewScaffold(),
NewChain(),
NewGenerate(),
NewNode(),
NewAccount(),
NewRelayer(),
NewTools(),
NewDocs(),
NewVersion(),
NewPlugin(),
NewDoctor(),
)
c.AddCommand(deprecated()...)

// Load plugins if any
Expand Down
6 changes: 4 additions & 2 deletions ignite/cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ func NewNode() *cobra.Command {

c.PersistentFlags().String(flagNode, cosmosRPCAddress, "<host>:<port> to tendermint rpc interface for this chain")

c.AddCommand(NewNodeQuery())
c.AddCommand(NewNodeTx())
c.AddCommand(
NewNodeQuery(),
NewNodeTx(),
)

return c
}
Expand Down
6 changes: 4 additions & 2 deletions ignite/cmd/node_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ func NewNodeQuery() *cobra.Command {
Aliases: []string{"q"},
}

c.AddCommand(NewNodeQueryBank())
c.AddCommand(NewNodeQueryTx())
c.AddCommand(
NewNodeQueryBank(),
NewNodeQueryTx(),
)

return c
}
Expand Down
14 changes: 8 additions & 6 deletions ignite/cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,14 @@ func NewPlugin() *cobra.Command {
Short: "Handle plugins",
}

c.AddCommand(NewPluginList())
c.AddCommand(NewPluginUpdate())
c.AddCommand(NewPluginScaffold())
c.AddCommand(NewPluginDescribe())
c.AddCommand(NewPluginAdd())
c.AddCommand(NewPluginRemove())
c.AddCommand(
NewPluginList(),
NewPluginUpdate(),
NewPluginScaffold(),
NewPluginDescribe(),
NewPluginAdd(),
NewPluginRemove(),
)

return c
}
Expand Down
44 changes: 29 additions & 15 deletions ignite/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package ignitecmd

import (
"errors"
"path/filepath"

"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

"github.com/ignite/cli/ignite/pkg/cliui"
"github.com/ignite/cli/ignite/pkg/gomodulepath"
"github.com/ignite/cli/ignite/pkg/placeholder"
"github.com/ignite/cli/ignite/pkg/xgit"
"github.com/ignite/cli/ignite/services/scaffolder"
Expand Down Expand Up @@ -90,19 +92,20 @@ with an "--ibc" flag. Note that the default module is not IBC-enabled.
Args: cobra.ExactArgs(1),
}

c.AddCommand(NewScaffoldChain())
c.AddCommand(NewScaffoldModule())
c.AddCommand(NewScaffoldList())
c.AddCommand(NewScaffoldMap())
c.AddCommand(NewScaffoldSingle())
c.AddCommand(NewScaffoldType())
c.AddCommand(NewScaffoldMessage())
c.AddCommand(NewScaffoldQuery())
c.AddCommand(NewScaffoldPacket())
c.AddCommand(NewScaffoldBandchain())
c.AddCommand(NewScaffoldVue())
c.AddCommand(NewScaffoldReact())
// c.AddCommand(NewScaffoldWasm())
c.AddCommand(
NewScaffoldChain(),
NewScaffoldModule(),
NewScaffoldList(),
NewScaffoldMap(),
NewScaffoldSingle(),
NewScaffoldType(),
NewScaffoldMessage(),
NewScaffoldQuery(),
NewScaffoldPacket(),
NewScaffoldBandchain(),
NewScaffoldVue(),
NewScaffoldReact(),
)

return c
}
Expand All @@ -115,11 +118,22 @@ func migrationPreRunHandler(cmd *cobra.Command, args []string) error {
session := cliui.New()
defer session.End()

if err := toolsMigrationPreRunHandler(cmd, session); err != nil {
path := flagGetPath(cmd)
path, err := filepath.Abs(path)
if err != nil {
return err
}

_, appPath, err := gomodulepath.Find(path)
if err != nil {
return err
}

if err := toolsMigrationPreRunHandler(cmd, session, appPath); err != nil {
return err
}

return bufMigrationPreRunHandler(cmd, session)
return bufMigrationPreRunHandler(cmd, session, appPath)
}

func scaffoldType(
Expand Down
6 changes: 4 additions & 2 deletions ignite/cmd/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ func NewTools() *cobra.Command {
Use: "tools",
Short: "Tools for advanced users",
}
c.AddCommand(NewToolsIBCSetup())
c.AddCommand(NewToolsIBCRelayer())
c.AddCommand(
NewToolsIBCSetup(),
NewToolsIBCRelayer(),
)
return c
}

Expand Down

0 comments on commit 3c6c598

Please sign in to comment.