Skip to content

Commit

Permalink
fix(cmd): re-enable cobra __complete command (#4033)
Browse files Browse the repository at this point in the history
* fix(cmd): re-enable cobra `__complete` command

* changelog

* nits

* nits

* updates

* updates
  • Loading branch information
julienrbrt authored Apr 4, 2024
1 parent bc57707 commit 777e64a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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`
Expand Down
15 changes: 7 additions & 8 deletions ignite/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"slices"
"strings"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -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
Expand All @@ -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 worlds
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.
Expand All @@ -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())
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down
5 changes: 4 additions & 1 deletion ignite/internal/tools/gen-cli-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 777e64a

Please sign in to comment.