Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmd): fix cobra completion #3905

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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" {

Check warning on line 64 in ignite/cmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/cmd.go#L64

Added line #L64 was not covered by tests
checkNewVersion(cmd.Context())
}

Expand All @@ -81,6 +81,7 @@
NewVersion(),
NewApp(),
NewDoctor(),
NewCompletionCmd(),

Check warning on line 84 in ignite/cmd/cmd.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/cmd.go#L84

Added line #L84 was not covered by tests
)
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
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()

Check warning on line 29 in ignite/cmd/completion.go

View check run for this annotation

Codecov / codecov/patch

ignite/cmd/completion.go#L10-L29

Added lines #L10 - L29 were not covered by tests
}
},
}
}
Loading