From 9961aa4973dcb7603abf80fb13c7610f33aaf575 Mon Sep 17 00:00:00 2001 From: Pantani Date: Tue, 23 Apr 2024 16:40:29 +0200 Subject: [PATCH 1/9] only use the proto dir from config --- ignite/cmd/chain.go | 17 ++++++------ ignite/cmd/cmd.go | 38 +++++++++++--------------- ignite/cmd/scaffold.go | 27 ++++++++++-------- ignite/cmd/scaffold_chain.go | 10 +++++-- ignite/cmd/scaffold_configs.go | 8 ++++-- ignite/cmd/scaffold_message.go | 8 ++++-- ignite/cmd/scaffold_module.go | 12 +++++--- ignite/cmd/scaffold_packet.go | 8 ++++-- ignite/cmd/scaffold_params.go | 8 ++++-- ignite/cmd/scaffold_query.go | 17 +++++++----- integration/app/cmd_proto_path_test.go | 14 ++++------ 11 files changed, 94 insertions(+), 73 deletions(-) diff --git a/ignite/cmd/chain.go b/ignite/cmd/chain.go index 83f54baaf9..97467df319 100644 --- a/ignite/cmd/chain.go +++ b/ignite/cmd/chain.go @@ -128,20 +128,20 @@ func preRunHandler(cmd *cobra.Command, _ []string) error { return err } - if err := configMigrationPreRunHandler(cmd, session, appPath); err != nil { + cfg, cfgPath, err := getChainConfig(cmd) + if err != nil { return err } - if err := toolsMigrationPreRunHandler(cmd, session, appPath); err != nil { + if err := configMigrationPreRunHandler(cmd, session, appPath, cfgPath); err != nil { return err } - protoDir, err := getProtoDirFromConfig(cmd) - if err != nil { + if err := toolsMigrationPreRunHandler(cmd, session, appPath); err != nil { return err } - return bufMigrationPreRunHandler(cmd, session, appPath, protoDir) + return bufMigrationPreRunHandler(cmd, session, appPath, cfg.Build.Proto.Path) } func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath string) error { @@ -254,8 +254,8 @@ func bufMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPa return nil } -func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath string) error { - rawCfg, configPath, err := getRawConfig(cmd) +func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath, cfgPath string) error { + rawCfg, err := os.ReadFile(cfgPath) if err != nil { return err } @@ -295,10 +295,9 @@ func configMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, ap return err } - if err := os.WriteFile(configPath, buf.Bytes(), 0o755); err != nil { + if err := os.WriteFile(cfgPath, buf.Bytes(), 0o755); err != nil { return errors.Errorf("config file migration failed: %w", err) } } - return nil } diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 123249f0a9..db3f67492a 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -1,7 +1,6 @@ package ignitecmd import ( - "bytes" "context" "fmt" "os" @@ -15,7 +14,6 @@ import ( "github.com/ignite/cli/v29/ignite/config" chainconfig "github.com/ignite/cli/v29/ignite/config/chain" - "github.com/ignite/cli/v29/ignite/config/chain/defaults" "github.com/ignite/cli/v29/ignite/pkg/cache" "github.com/ignite/cli/v29/ignite/pkg/cliui" uilog "github.com/ignite/cli/v29/ignite/pkg/cliui/log" @@ -32,6 +30,9 @@ const ( flagClearCache = "clear-cache" flagSkipProto = "skip-proto" + ctxChainConfig = "chain-config" + ctxChainConfigPath = "chain-config-path" + checkVersionTimeout = time.Millisecond * 600 cacheFileName = "ignite_cache.db" @@ -134,17 +135,6 @@ func getHome(cmd *cobra.Command) (home string) { return } -func flagSetProtoDir() *flag.FlagSet { - fs := flag.NewFlagSet("", flag.ContinueOnError) - fs.String(flagProtoDir, defaults.ProtoDir, "chain proto directory") - return fs -} - -func flagGetProtoDir(cmd *cobra.Command) (config string) { - config, _ = cmd.Flags().GetString(flagProtoDir) - return -} - func flagSetConfig() *flag.FlagSet { fs := flag.NewFlagSet("", flag.ContinueOnError) fs.StringP(flagConfig, "c", "", "path to Ignite config file (default: ./config.yml)") @@ -156,7 +146,12 @@ func getConfig(cmd *cobra.Command) (config string) { return } -func getRawConfig(cmd *cobra.Command) ([]byte, string, error) { +func getChainConfig(cmd *cobra.Command) (*chainconfig.Config, string, error) { + cfg, ok := cmd.Context().Value(ctxChainConfig).(*chainconfig.Config) + if ok { + configPath := cmd.Context().Value(ctxChainConfigPath).(string) + return cfg, configPath, nil + } configPath := getConfig(cmd) path := flagGetPath(cmd) @@ -171,16 +166,15 @@ func getRawConfig(cmd *cobra.Command) ([]byte, string, error) { } } - rawConfig, err := os.ReadFile(configPath) - return rawConfig, configPath, err -} - -func getProtoDirFromConfig(cmd *cobra.Command) (string, error) { - rawCfg, _, err := getRawConfig(cmd) + cfg, err = chainconfig.ParseFile(configPath) if err != nil { - return "", err + return nil, "", err } - return chainconfig.ReadProtoPath(bytes.NewReader(rawCfg)) + ctx := context.WithValue(cmd.Context(), ctxChainConfig, cfg) + ctx = context.WithValue(ctx, ctxChainConfigPath, configPath) + cmd.SetContext(ctx) + + return cfg, configPath, err } func flagSetYes() *flag.FlagSet { diff --git a/ignite/cmd/scaffold.go b/ignite/cmd/scaffold.go index e3917316d9..6d008e53e4 100644 --- a/ignite/cmd/scaffold.go +++ b/ignite/cmd/scaffold.go @@ -23,7 +23,6 @@ const ( flagNoSimulation = "no-simulation" flagResponse = "response" flagDescription = "desc" - flagProtoDir = "proto-dir" msgCommitPrefix = "Your saved project changes have not been committed.\nTo enable reverting to your current state, commit your saved changes." msgCommitPrompt = "Do you want to proceed without committing your saved changes" @@ -132,9 +131,6 @@ with an "--ibc" flag. Note that the default module is not IBC-enabled. NewScaffoldReact(), ) - // Add flags required for the configMigrationPreRunHandler - c.PersistentFlags().AddFlagSet(flagSetProtoDir()) - return c } @@ -144,12 +140,17 @@ func migrationPreRunHandler(cmd *cobra.Command, args []string) error { } var ( - path = flagGetPath(cmd) - protoDir = flagGetProtoDir(cmd) - session = cliui.New() + path = flagGetPath(cmd) + session = cliui.New() ) defer session.End() - path, err := filepath.Abs(path) + + cfg, _, err := getChainConfig(cmd) + if err != nil { + return err + } + + path, err = filepath.Abs(path) if err != nil { return err } @@ -172,7 +173,7 @@ func migrationPreRunHandler(cmd *cobra.Command, args []string) error { return err } - return bufMigrationPreRunHandler(cmd, session, appPath, protoDir) + return bufMigrationPreRunHandler(cmd, session, appPath, cfg.Build.Proto.Path) } func scaffoldType( @@ -188,7 +189,6 @@ func scaffoldType( withoutSimulation = flagGetNoSimulation(cmd) signer = flagGetSigner(cmd) appPath = flagGetPath(cmd) - protoDir = flagGetProtoDir(cmd) ) var options []scaffolder.AddTypeOption @@ -213,7 +213,12 @@ func scaffoldType( session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding)) defer session.End() - sc, err := scaffolder.New(cmd.Context(), appPath, protoDir) + cfg, _, err := getChainConfig(cmd) + if err != nil { + return err + } + + sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path) if err != nil { return err } diff --git a/ignite/cmd/scaffold_chain.go b/ignite/cmd/scaffold_chain.go index 8baf897aea..a25d439cd8 100644 --- a/ignite/cmd/scaffold_chain.go +++ b/ignite/cmd/scaffold_chain.go @@ -102,7 +102,6 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { name = args[0] addressPrefix = getAddressPrefix(cmd) appPath = flagGetPath(cmd) - protoDir = flagGetProtoDir(cmd) noDefaultModule, _ = cmd.Flags().GetBool(flagNoDefaultModule) skipGit, _ = cmd.Flags().GetBool(flagSkipGit) minimal, _ = cmd.Flags().GetBool(flagMinimal) @@ -120,6 +119,11 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { } } + cfg, _, err := getChainConfig(cmd) + if err != nil { + return err + } + cacheStorage, err := newCache(cmd) if err != nil { return err @@ -132,7 +136,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { appPath, name, addressPrefix, - protoDir, + cfg.Build.Proto.Path, noDefaultModule, minimal, isConsumer, @@ -152,7 +156,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { return err } - if err := scaffolder.PostScaffold(cmd.Context(), cacheStorage, appDir, protoDir, goModule, skipProto); err != nil { + if err := scaffolder.PostScaffold(cmd.Context(), cacheStorage, appDir, cfg.Build.Proto.Path, goModule, skipProto); err != nil { return err } diff --git a/ignite/cmd/scaffold_configs.go b/ignite/cmd/scaffold_configs.go index a1d97dfc71..955471d8e8 100644 --- a/ignite/cmd/scaffold_configs.go +++ b/ignite/cmd/scaffold_configs.go @@ -46,18 +46,22 @@ func scaffoldConfigsHandler(cmd *cobra.Command, args []string) error { configs = args[0:] appPath = flagGetPath(cmd) moduleName = flagGetModule(cmd) - protoDir = flagGetProtoDir(cmd) ) session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding)) defer session.End() + cfg, _, err := getChainConfig(cmd) + if err != nil { + return err + } + cacheStorage, err := newCache(cmd) if err != nil { return err } - sc, err := scaffolder.New(cmd.Context(), appPath, protoDir) + sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path) if err != nil { return err } diff --git a/ignite/cmd/scaffold_message.go b/ignite/cmd/scaffold_message.go index 0db510ac47..cab6b2a588 100644 --- a/ignite/cmd/scaffold_message.go +++ b/ignite/cmd/scaffold_message.go @@ -86,12 +86,16 @@ func messageHandler(cmd *cobra.Command, args []string) error { signer = flagGetSigner(cmd) appPath = flagGetPath(cmd) withoutSimulation = flagGetNoSimulation(cmd) - protoDir = flagGetProtoDir(cmd) ) session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding)) defer session.End() + cfg, _, err := getChainConfig(cmd) + if err != nil { + return err + } + cacheStorage, err := newCache(cmd) if err != nil { return err @@ -114,7 +118,7 @@ func messageHandler(cmd *cobra.Command, args []string) error { options = append(options, scaffolder.WithoutSimulation()) } - sc, err := scaffolder.New(cmd.Context(), appPath, protoDir) + sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path) if err != nil { return err } diff --git a/ignite/cmd/scaffold_module.go b/ignite/cmd/scaffold_module.go index 8a81d623c6..98a1576a8f 100644 --- a/ignite/cmd/scaffold_module.go +++ b/ignite/cmd/scaffold_module.go @@ -114,14 +114,18 @@ params. func scaffoldModuleHandler(cmd *cobra.Command, args []string) error { var ( - name = args[0] - appPath = flagGetPath(cmd) - protoDir = flagGetProtoDir(cmd) + name = args[0] + appPath = flagGetPath(cmd) ) session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding)) defer session.End() + cfg, _, err := getChainConfig(cmd) + if err != nil { + return err + } + ibcModule, _ := cmd.Flags().GetBool(flagIBC) ibcOrdering, _ := cmd.Flags().GetString(flagIBCOrdering) requireRegistration, _ := cmd.Flags().GetBool(flagRequireRegistration) @@ -172,7 +176,7 @@ func scaffoldModuleHandler(cmd *cobra.Command, args []string) error { var msg bytes.Buffer fmt.Fprintf(&msg, "\nšŸŽ‰ Module created %s.\n\n", name) - sc, err := scaffolder.New(cmd.Context(), appPath, protoDir) + sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path) if err != nil { return err } diff --git a/ignite/cmd/scaffold_packet.go b/ignite/cmd/scaffold_packet.go index 6923952c61..c4f70b6fcc 100644 --- a/ignite/cmd/scaffold_packet.go +++ b/ignite/cmd/scaffold_packet.go @@ -41,12 +41,16 @@ func createPacketHandler(cmd *cobra.Command, args []string) error { packetFields = args[1:] signer = flagGetSigner(cmd) appPath = flagGetPath(cmd) - protoDir = flagGetProtoDir(cmd) ) session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding)) defer session.End() + cfg, _, err := getChainConfig(cmd) + if err != nil { + return err + } + module, _ := cmd.Flags().GetString(flagModule) if module == "" { return errors.New("please specify a module to create the packet into: --module ") @@ -67,7 +71,7 @@ func createPacketHandler(cmd *cobra.Command, args []string) error { options = append(options, scaffolder.PacketWithSigner(signer)) } - sc, err := scaffolder.New(cmd.Context(), appPath, protoDir) + sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path) if err != nil { return err } diff --git a/ignite/cmd/scaffold_params.go b/ignite/cmd/scaffold_params.go index 38b7534e94..78fb6f7ef9 100644 --- a/ignite/cmd/scaffold_params.go +++ b/ignite/cmd/scaffold_params.go @@ -48,18 +48,22 @@ func scaffoldParamsHandler(cmd *cobra.Command, args []string) error { params = args[0:] appPath = flagGetPath(cmd) moduleName = flagGetModule(cmd) - protoDir = flagGetProtoDir(cmd) ) session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding)) defer session.End() + cfg, _, err := getChainConfig(cmd) + if err != nil { + return err + } + cacheStorage, err := newCache(cmd) if err != nil { return err } - sc, err := scaffolder.New(cmd.Context(), appPath, protoDir) + sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path) if err != nil { return err } diff --git a/ignite/cmd/scaffold_query.go b/ignite/cmd/scaffold_query.go index bd09bf44a8..6d80008f99 100644 --- a/ignite/cmd/scaffold_query.go +++ b/ignite/cmd/scaffold_query.go @@ -39,14 +39,14 @@ For detailed type information use ignite scaffold type --help.`, } func queryHandler(cmd *cobra.Command, args []string) error { - var ( - appPath = flagGetPath(cmd) - protoDir = flagGetProtoDir(cmd) - ) - session := cliui.New(cliui.StartSpinnerWithText(statusScaffolding)) defer session.End() + cfg, _, err := getChainConfig(cmd) + if err != nil { + return err + } + // Get the module to add the type into module, _ := cmd.Flags().GetString(flagModule) @@ -60,14 +60,17 @@ func queryHandler(cmd *cobra.Command, args []string) error { desc = fmt.Sprintf("Query %s", args[0]) } - paginated, _ := cmd.Flags().GetBool(flagPaginated) + var ( + paginated, _ = cmd.Flags().GetBool(flagPaginated) + appPath = flagGetPath(cmd) + ) cacheStorage, err := newCache(cmd) if err != nil { return err } - sc, err := scaffolder.New(cmd.Context(), appPath, protoDir) + sc, err := scaffolder.New(cmd.Context(), appPath, cfg.Build.Proto.Path) if err != nil { return err } diff --git a/integration/app/cmd_proto_path_test.go b/integration/app/cmd_proto_path_test.go index ce54439c70..ad8c243452 100644 --- a/integration/app/cmd_proto_path_test.go +++ b/integration/app/cmd_proto_path_test.go @@ -61,7 +61,7 @@ var ( func TestChangeProtoPath(t *testing.T) { var ( env = envtest.New(t) - app = env.Scaffold("github.com/test/protopath", "--proto-dir", newProtoPath) + app = env.Scaffold("github.com/test/protopath") appPath = app.SourcePath() cfgPath = filepath.Join(appPath, chain.ConfigFilenames[0]) ) @@ -75,28 +75,28 @@ func TestChangeProtoPath(t *testing.T) { env.Must(env.Exec("create a list with a custom proto path", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "s", "list", "--yes", "listUser", "email", "--proto-dir", newProtoPath), + step.Exec(envtest.IgniteApp, "s", "list", "--yes", "listUser", "email"), step.Workdir(app.SourcePath()), )), )) env.Must(env.Exec("create a map with a custom proto path", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "s", "map", "--yes", "mapUser", "email", "--proto-dir", newProtoPath), + step.Exec(envtest.IgniteApp, "s", "map", "--yes", "mapUser", "email"), step.Workdir(app.SourcePath()), )), )) env.Must(env.Exec("create a single with a custom proto path", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "s", "single", "--yes", "singleUser", "email", "--proto-dir", newProtoPath), + step.Exec(envtest.IgniteApp, "s", "single", "--yes", "singleUser", "email"), step.Workdir(app.SourcePath()), )), )) env.Must(env.Exec("create a query with a custom proto path", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "s", "query", "--yes", "foo", "--proto-dir", newProtoPath), + step.Exec(envtest.IgniteApp, "s", "query", "--yes", "foo", "--proto-dir"), step.Workdir(app.SourcePath()), )), )) @@ -111,8 +111,6 @@ func TestChangeProtoPath(t *testing.T) { "--params", "bla,baz:uint", "--require-registration", - "-p", - newProtoPath, ), step.Workdir(app.SourcePath()), )), @@ -128,8 +126,6 @@ func TestChangeProtoPath(t *testing.T) { "bar:int", "--module", "foo", - "-p", - newProtoPath, ), step.Workdir(app.SourcePath()), )), From e52b340cdab667814e7952d06ddd3534fec72253 Mon Sep 17 00:00:00 2001 From: Pantani Date: Wed, 24 Apr 2024 02:35:37 +0200 Subject: [PATCH 2/9] add proto dir only for scaffold a new chain --- ignite/cmd/scaffold.go | 1 + ignite/cmd/scaffold_chain.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/ignite/cmd/scaffold.go b/ignite/cmd/scaffold.go index 6d008e53e4..becacdd26d 100644 --- a/ignite/cmd/scaffold.go +++ b/ignite/cmd/scaffold.go @@ -23,6 +23,7 @@ const ( flagNoSimulation = "no-simulation" flagResponse = "response" flagDescription = "desc" + flagProtoDir = "proto-dir" msgCommitPrefix = "Your saved project changes have not been committed.\nTo enable reverting to your current state, commit your saved changes." msgCommitPrompt = "Do you want to proceed without committing your saved changes" diff --git a/ignite/cmd/scaffold_chain.go b/ignite/cmd/scaffold_chain.go index a25d439cd8..a51689f035 100644 --- a/ignite/cmd/scaffold_chain.go +++ b/ignite/cmd/scaffold_chain.go @@ -3,6 +3,7 @@ package ignitecmd import ( "github.com/spf13/cobra" + "github.com/ignite/cli/v29/ignite/config/chain/defaults" "github.com/ignite/cli/v29/ignite/pkg/cliui" "github.com/ignite/cli/v29/ignite/pkg/errors" "github.com/ignite/cli/v29/ignite/pkg/xfilepath" @@ -88,6 +89,8 @@ about Cosmos SDK on https://docs.cosmos.network c.Flags().Bool(flagSkipProto, false, "skip proto generation") c.Flags().Bool(flagMinimal, false, "create a minimal blockchain (with the minimum required Cosmos SDK modules)") c.Flags().Bool(flagIsConsumer, false, "scafffold an ICS consumer chain") + c.Flags().String(flagProtoDir, defaults.ProtoDir, "chain proto directory") + // Cannot have both minimal and consumer flag c.MarkFlagsMutuallyExclusive(flagIsConsumer, flagMinimal) @@ -99,9 +102,10 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { defer session.End() var ( - name = args[0] - addressPrefix = getAddressPrefix(cmd) - appPath = flagGetPath(cmd) + name = args[0] + addressPrefix = getAddressPrefix(cmd) + appPath = flagGetPath(cmd) + noDefaultModule, _ = cmd.Flags().GetBool(flagNoDefaultModule) skipGit, _ = cmd.Flags().GetBool(flagSkipGit) minimal, _ = cmd.Flags().GetBool(flagMinimal) @@ -109,6 +113,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { params, _ = cmd.Flags().GetStringSlice(flagParams) moduleConfigs, _ = cmd.Flags().GetStringSlice(flagModuleConfigs) skipProto, _ = cmd.Flags().GetBool(flagSkipProto) + protoDir, _ = cmd.Flags().GetString(flagProtoDir) ) if noDefaultModule { @@ -119,11 +124,6 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { } } - cfg, _, err := getChainConfig(cmd) - if err != nil { - return err - } - cacheStorage, err := newCache(cmd) if err != nil { return err @@ -136,7 +136,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { appPath, name, addressPrefix, - cfg.Build.Proto.Path, + protoDir, noDefaultModule, minimal, isConsumer, @@ -156,7 +156,7 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error { return err } - if err := scaffolder.PostScaffold(cmd.Context(), cacheStorage, appDir, cfg.Build.Proto.Path, goModule, skipProto); err != nil { + if err := scaffolder.PostScaffold(cmd.Context(), cacheStorage, appDir, protoDir, goModule, skipProto); err != nil { return err } From 00b2a22e8d9f0f35b03c8347fee0120770cc148d Mon Sep 17 00:00:00 2001 From: Pantani Date: Wed, 24 Apr 2024 02:38:08 +0200 Subject: [PATCH 3/9] add changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 3d36b0cecf..1aa4a23a84 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,7 @@ - [#4071](https://github.com/ignite/cli/pull/4071) Support custom proto path - [#3718](https://github.com/ignite/cli/pull/3718) Add `gen-mig-diffs` tool app to compare scaffold output of two versions of ignite - [#4077](https://github.com/ignite/cli/pull/4077) Merge the swagger files manually instead use nodetime `swagger-combine` +- [#4100](https://github.com/ignite/cli/pull/4100) Set the `proto-dir` flag only for the `scaffold chain` command and use the proto path from the config ### Changes From 0a27a9f05f9c4639124d697a20a77837446d75bf Mon Sep 17 00:00:00 2001 From: Pantani Date: Wed, 24 Apr 2024 02:42:03 +0200 Subject: [PATCH 4/9] fix integartion tests --- integration/app/cmd_proto_path_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/app/cmd_proto_path_test.go b/integration/app/cmd_proto_path_test.go index ad8c243452..7fa177f5b4 100644 --- a/integration/app/cmd_proto_path_test.go +++ b/integration/app/cmd_proto_path_test.go @@ -61,7 +61,7 @@ var ( func TestChangeProtoPath(t *testing.T) { var ( env = envtest.New(t) - app = env.Scaffold("github.com/test/protopath") + app = env.Scaffold("github.com/test/protopath", "--proto-dir", newProtoPath) appPath = app.SourcePath() cfgPath = filepath.Join(appPath, chain.ConfigFilenames[0]) ) From 7e7569528a14356d11e77b0f3e79b45939e780ee Mon Sep 17 00:00:00 2001 From: Pantani Date: Wed, 24 Apr 2024 02:43:06 +0200 Subject: [PATCH 5/9] remove unused flag from integration tests cmds --- integration/app/cmd_proto_path_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/app/cmd_proto_path_test.go b/integration/app/cmd_proto_path_test.go index 7fa177f5b4..9b2b404a6d 100644 --- a/integration/app/cmd_proto_path_test.go +++ b/integration/app/cmd_proto_path_test.go @@ -96,7 +96,7 @@ func TestChangeProtoPath(t *testing.T) { env.Must(env.Exec("create a query with a custom proto path", step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "s", "query", "--yes", "foo", "--proto-dir"), + step.Exec(envtest.IgniteApp, "s", "query", "--yes", "foo"), step.Workdir(app.SourcePath()), )), )) From 49f1cd2b48374cc80c6e0df0504c9fe246ff8ac9 Mon Sep 17 00:00:00 2001 From: Pantani Date: Wed, 24 Apr 2024 02:51:53 +0200 Subject: [PATCH 6/9] fix revive lint use --- ignite/cmd/cmd.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index db3f67492a..3a3733d1d5 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -23,6 +23,13 @@ import ( "github.com/ignite/cli/v29/ignite/version" ) +type key int + +const ( + keyChainConfig key = iota + keyChainConfigPath key = iota +) + const ( flagPath = "path" flagHome = "home" @@ -30,9 +37,6 @@ const ( flagClearCache = "clear-cache" flagSkipProto = "skip-proto" - ctxChainConfig = "chain-config" - ctxChainConfigPath = "chain-config-path" - checkVersionTimeout = time.Millisecond * 600 cacheFileName = "ignite_cache.db" @@ -147,9 +151,9 @@ func getConfig(cmd *cobra.Command) (config string) { } func getChainConfig(cmd *cobra.Command) (*chainconfig.Config, string, error) { - cfg, ok := cmd.Context().Value(ctxChainConfig).(*chainconfig.Config) + cfg, ok := cmd.Context().Value(keyChainConfig).(*chainconfig.Config) if ok { - configPath := cmd.Context().Value(ctxChainConfigPath).(string) + configPath := cmd.Context().Value(keyChainConfigPath).(string) return cfg, configPath, nil } configPath := getConfig(cmd) @@ -170,8 +174,8 @@ func getChainConfig(cmd *cobra.Command) (*chainconfig.Config, string, error) { if err != nil { return nil, "", err } - ctx := context.WithValue(cmd.Context(), ctxChainConfig, cfg) - ctx = context.WithValue(ctx, ctxChainConfigPath, configPath) + ctx := context.WithValue(cmd.Context(), keyChainConfig, cfg) + ctx = context.WithValue(ctx, keyChainConfigPath, configPath) cmd.SetContext(ctx) return cfg, configPath, err From 7074716d7a1d637367711db3e3d0a93199337fd7 Mon Sep 17 00:00:00 2001 From: Pantani Date: Wed, 24 Apr 2024 03:11:51 +0200 Subject: [PATCH 7/9] add a helper to find the root chain path --- ignite/cmd/chain.go | 9 +-------- ignite/cmd/cmd.go | 18 ++++++++++++++++-- ignite/cmd/scaffold.go | 15 ++------------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/ignite/cmd/chain.go b/ignite/cmd/chain.go index 97467df319..c18ad70eb7 100644 --- a/ignite/cmd/chain.go +++ b/ignite/cmd/chain.go @@ -17,7 +17,6 @@ import ( "github.com/ignite/cli/v29/ignite/pkg/cosmosgen" "github.com/ignite/cli/v29/ignite/pkg/errors" "github.com/ignite/cli/v29/ignite/pkg/goanalysis" - "github.com/ignite/cli/v29/ignite/pkg/gomodulepath" "github.com/ignite/cli/v29/ignite/pkg/xast" "github.com/ignite/cli/v29/ignite/pkg/xgenny" "github.com/ignite/cli/v29/ignite/services/chain" @@ -117,13 +116,7 @@ func preRunHandler(cmd *cobra.Command, _ []string) error { session := cliui.New() defer session.End() - path := flagGetPath(cmd) - path, err := filepath.Abs(path) - if err != nil { - return err - } - - _, appPath, err := gomodulepath.Find(path) + appPath, err := goModulePath(cmd) if err != nil { return err } diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 3a3733d1d5..5e2d7cfbb3 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -20,6 +20,7 @@ import ( "github.com/ignite/cli/v29/ignite/pkg/errors" "github.com/ignite/cli/v29/ignite/pkg/gitpod" "github.com/ignite/cli/v29/ignite/pkg/goenv" + "github.com/ignite/cli/v29/ignite/pkg/gomodulepath" "github.com/ignite/cli/v29/ignite/version" ) @@ -128,6 +129,20 @@ func flagGetPath(cmd *cobra.Command) (path string) { return } +func goModulePath(cmd *cobra.Command) (string, error) { + path := flagGetPath(cmd) + path, err := filepath.Abs(path) + if err != nil { + return "", err + } + + _, appPath, err := gomodulepath.Find(path) + if err != nil { + return "", err + } + return appPath, err +} + func flagSetHome() *flag.FlagSet { fs := flag.NewFlagSet("", flag.ContinueOnError) fs.String(flagHome, "", "directory where the blockchain node is initialized") @@ -158,8 +173,7 @@ func getChainConfig(cmd *cobra.Command) (*chainconfig.Config, string, error) { } configPath := getConfig(cmd) - path := flagGetPath(cmd) - path, err := filepath.Abs(path) + path, err := goModulePath(cmd) if err != nil { return nil, "", err } diff --git a/ignite/cmd/scaffold.go b/ignite/cmd/scaffold.go index becacdd26d..e3902ed888 100644 --- a/ignite/cmd/scaffold.go +++ b/ignite/cmd/scaffold.go @@ -1,8 +1,6 @@ package ignitecmd import ( - "path/filepath" - "github.com/manifoldco/promptui" "github.com/spf13/cobra" flag "github.com/spf13/pflag" @@ -10,7 +8,6 @@ import ( "github.com/ignite/cli/v29/ignite/pkg/cliui" "github.com/ignite/cli/v29/ignite/pkg/cosmosver" "github.com/ignite/cli/v29/ignite/pkg/errors" - "github.com/ignite/cli/v29/ignite/pkg/gomodulepath" "github.com/ignite/cli/v29/ignite/pkg/xgit" "github.com/ignite/cli/v29/ignite/services/scaffolder" "github.com/ignite/cli/v29/ignite/version" @@ -140,10 +137,7 @@ func migrationPreRunHandler(cmd *cobra.Command, args []string) error { return err } - var ( - path = flagGetPath(cmd) - session = cliui.New() - ) + session := cliui.New() defer session.End() cfg, _, err := getChainConfig(cmd) @@ -151,12 +145,7 @@ func migrationPreRunHandler(cmd *cobra.Command, args []string) error { return err } - path, err = filepath.Abs(path) - if err != nil { - return err - } - - _, appPath, err := gomodulepath.Find(path) + appPath, err := goModulePath(cmd) if err != nil { return err } From a2b0eb87b78fdd83a88647553468566d54de9974 Mon Sep 17 00:00:00 2001 From: Pantani Date: Thu, 25 Apr 2024 01:07:38 +0200 Subject: [PATCH 8/9] remove unused method --- ignite/config/chain/parse.go | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ignite/config/chain/parse.go b/ignite/config/chain/parse.go index 309d66eb2c..bc23cb4b91 100644 --- a/ignite/config/chain/parse.go +++ b/ignite/config/chain/parse.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/types/bech32" "gopkg.in/yaml.v3" - "github.com/ignite/cli/v29/ignite/config/chain/defaults" "github.com/ignite/cli/v29/ignite/config/chain/version" "github.com/ignite/cli/v29/ignite/pkg/errors" ) @@ -103,26 +102,6 @@ func ReadConfigVersion(configFile io.Reader) (version.Version, error) { return c.Version, err } -// ReadProtoPath reads the build proto path from the config. -func ReadProtoPath(configFile io.Reader) (string, error) { - c := struct { - Build struct { - Proto struct { - Path string `yaml:"path"` - } `yaml:"proto"` - } `yaml:"build"` - }{} - - if err := yaml.NewDecoder(configFile).Decode(&c); err != nil { - return "", err - } - path := c.Build.Proto.Path - if path == "" { - path = defaults.ProtoDir - } - return path, nil -} - func decodeConfig(r io.Reader, version version.Version) (version.Converter, error) { c, ok := Versions[version] if !ok { From 43622717ee3207d1de735eee6be96d0f33569279 Mon Sep 17 00:00:00 2001 From: Pantani Date: Thu, 25 Apr 2024 01:09:48 +0200 Subject: [PATCH 9/9] remove unused tests --- integration/app/cmd_proto_path_test.go | 53 +------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/integration/app/cmd_proto_path_test.go b/integration/app/cmd_proto_path_test.go index 9b2b404a6d..ae2f207df1 100644 --- a/integration/app/cmd_proto_path_test.go +++ b/integration/app/cmd_proto_path_test.go @@ -73,63 +73,12 @@ func TestChangeProtoPath(t *testing.T) { require.NoError(t, file.Close()) app.SetConfigPath(cfgPath) - env.Must(env.Exec("create a list with a custom proto path", + env.Must(env.Exec("create a list with a custom proto path from config", step.NewSteps(step.New( step.Exec(envtest.IgniteApp, "s", "list", "--yes", "listUser", "email"), step.Workdir(app.SourcePath()), )), )) - env.Must(env.Exec("create a map with a custom proto path", - step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "s", "map", "--yes", "mapUser", "email"), - step.Workdir(app.SourcePath()), - )), - )) - - env.Must(env.Exec("create a single with a custom proto path", - step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "s", "single", "--yes", "singleUser", "email"), - step.Workdir(app.SourcePath()), - )), - )) - - env.Must(env.Exec("create a query with a custom proto path", - step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, "s", "query", "--yes", "foo"), - step.Workdir(app.SourcePath()), - )), - )) - - env.Must(env.Exec("create a new module with parameter", - step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, - "s", - "module", - "--yes", - "foo", - "--params", - "bla,baz:uint", - "--require-registration", - ), - step.Workdir(app.SourcePath()), - )), - )) - - env.Must(env.Exec("create a new module parameter in the mars module", - step.NewSteps(step.New( - step.Exec(envtest.IgniteApp, - "s", - "params", - "--yes", - "foo", - "bar:int", - "--module", - "foo", - ), - step.Workdir(app.SourcePath()), - )), - )) - app.EnsureSteady() }