Skip to content

Commit

Permalink
fix(cmd): fix cobra completion (#3905)
Browse files Browse the repository at this point in the history
* fix(cmd): fix cobra completion

* updates
  • Loading branch information
julienrbrt committed Jan 25, 2024
1 parent f96ab07 commit 18e5fc9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

- [#3835](https://github.com/ignite/cli/pull/3835) Add `--minimal` flag to `scaffold chain` to scaffold a chain with the least amount of sdk modules


### Changes

- [#3899](https://github.com/ignite/cli/pull/3899) Introduce plugin.Execute function

### Bug Fixes

- [#3905](https://github.com/ignite/cli/pull/3905) Fix `ignite completion`

## [`v28.1.1`](https://github.com/ignite/cli/releases/tag/v28.1.1)

### Fixes
Expand Down
3 changes: 2 additions & 1 deletion ignite/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ To get started, create a blockchain:
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 != "completions" {
if cmd.Use != "completion" {
checkNewVersion(cmd.Context())
}

Expand All @@ -81,6 +81,7 @@ To get started, create a blockchain:
NewVersion(),
NewApp(),
NewDoctor(),
NewCompletionCmd(),
)
c.AddCommand(deprecated()...)

Expand Down
33 changes: 33 additions & 0 deletions ignite/cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ignitecmd

import (
"os"

"github.com/spf13/cobra"
)

// completionCmd represents the completion command

Check failure on line 9 in ignite/cmd/completion.go

View workflow job for this annotation

GitHub Actions / Lint Go code

Comment should end in a period (godot)
func NewCompletionCmd() *cobra.Command {
return &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generates shell completion script.",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
os.Exit(0)
}
switch args[0] {
case "bash":
cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
cmd.Root().GenPowerShellCompletion(os.Stdout)
default:
cmd.Help()
}
},
}
}

0 comments on commit 18e5fc9

Please sign in to comment.