From 777e64a4ffe4e002b5111cc406921d3363d09761 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 4 Apr 2024 09:43:41 +0200 Subject: [PATCH] fix(cmd): re-enable cobra `__complete` command (#4033) * fix(cmd): re-enable cobra `__complete` command * changelog * nits * nits * updates * updates --- changelog.md | 1 + ignite/cmd/cmd.go | 15 +++++++-------- ignite/cmd/completion.go | 2 +- ignite/internal/tools/gen-cli-docs/main.go | 5 ++++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/changelog.md b/changelog.md index f705c3e608..e572d36540 100644 --- a/changelog.md +++ b/changelog.md @@ -47,6 +47,7 @@ ### Fixes +- [#4033](https://github.com/ignite/cli/pull/4033) Fix cobra completion using `fishshell` - [#4021](https://github.com/ignite/cli/pull/4021) Set correct custom signer in `s list --signer ` - [#3995](https://github.com/ignite/cli/pull/3995) Fix interface check for ibc modules - [#3953](https://github.com/ignite/cli/pull/3953) Fix apps `Stdout` is redirected to `Stderr` diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index 16e678c916..622b84a048 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" "slices" + "strings" "time" "github.com/spf13/cobra" @@ -36,7 +37,7 @@ const ( ) // List of CLI level one commands that should not load Ignite app instances. -var skipAppsLoadCommands = []string{"version", "help", "docs", "completion"} +var skipAppsLoadCommands = []string{"version", "help", "docs", "completion", cobra.ShellCompRequestCmd, cobra.ShellCompNoDescRequestCmd} // New creates a new root command for `Ignite CLI` with its sub commands. // Returns the cobra.Command, a cleanup function and an error. The cleanup @@ -47,7 +48,7 @@ func New(ctx context.Context) (*cobra.Command, func(), error) { c := &cobra.Command{ Use: "ignite", Short: "Ignite CLI offers everything you need to scaffold, test, build, and launch your blockchain", - Long: `Ignite CLI is a tool for creating sovereign blockchains built with Cosmos SDK, the world’s + Long: `Ignite CLI is a tool for creating sovereign blockchains built with Cosmos SDK, the world's most popular modular blockchain framework. Ignite CLI offers everything you need to scaffold, test, build, and launch your blockchain. @@ -57,10 +58,11 @@ To get started, create a blockchain: `, SilenceUsage: true, SilenceErrors: true, + Args: cobra.MinimumNArgs(0), // note(@julienrbrt): without this, ignite __complete(noDesc) hidden commands are not working. PersistentPreRunE: func(cmd *cobra.Command, args []string) error { // Check for new versions only when shell completion scripts are not being // generated to avoid invalid output to stdout when a new version is available - if cmd.Use != "completion" { + if cmd.Use != "completion" || !strings.HasPrefix(cmd.Use, cobra.ShellCompRequestCmd) { checkNewVersion(cmd.Context()) } @@ -83,9 +85,10 @@ To get started, create a blockchain: NewCompletionCmd(), ) c.AddCommand(deprecated()...) + c.SetContext(ctx) // Don't load Ignite apps for level one commands that doesn't allow them - if len(os.Args) == 2 && slices.Contains(skipAppsLoadCommands, os.Args[1]) { + if len(os.Args) >= 2 && slices.Contains(skipAppsLoadCommands, os.Args[1]) { return c, func() {}, nil } @@ -172,10 +175,6 @@ func flagGetClearCache(cmd *cobra.Command) bool { func deprecated() []*cobra.Command { return []*cobra.Command{ - { - Use: "app", - Deprecated: "use `ignite scaffold chain` instead.", - }, { Use: "build", Deprecated: "use `ignite chain build` instead.", diff --git a/ignite/cmd/completion.go b/ignite/cmd/completion.go index ffe0700a93..385a36ff1d 100644 --- a/ignite/cmd/completion.go +++ b/ignite/cmd/completion.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -// completionCmd represents the completion command. +// NewCompletionCmd represents the completion command. func NewCompletionCmd() *cobra.Command { return &cobra.Command{ Use: "completion [bash|zsh|fish|powershell]", diff --git a/ignite/internal/tools/gen-cli-docs/main.go b/ignite/internal/tools/gen-cli-docs/main.go index 3023fa363c..7076da90bb 100644 --- a/ignite/internal/tools/gen-cli-docs/main.go +++ b/ignite/internal/tools/gen-cli-docs/main.go @@ -73,7 +73,10 @@ func run(outPath string) error { defer cleanUp() // Run ExecuteC so cobra adds the completion command. - cmd, _ = cmd.ExecuteC() + cmd, err = cmd.ExecuteC() + if err != nil { + return err + } return generate(cmd, outPath) }