From 92af14543ba3ad1b662e8a4dcd7612831da783ec Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 24 Jan 2024 23:58:30 +0100 Subject: [PATCH 1/2] fix(cmd): fix cobra completion --- changelog.md | 5 ++++- ignite/cmd/cmd.go | 3 ++- ignite/cmd/completion.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 ignite/cmd/completion.go diff --git a/changelog.md b/changelog.md index 31622461d9..e33266dde8 100644 --- a/changelog.md +++ b/changelog.md @@ -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 + +- [#3896](https://github.com/ignite/cli/issues/3896) Fix `ignite completion` + ## [`v28.1.1`](https://github.com/ignite/cli/releases/tag/v28.1.1) ### Fixes diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index a30811e180..fe07aec6c7 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -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()) } @@ -81,6 +81,7 @@ To get started, create a blockchain: NewVersion(), NewApp(), NewDoctor(), + NewCompletionCmd(), ) c.AddCommand(deprecated()...) diff --git a/ignite/cmd/completion.go b/ignite/cmd/completion.go new file mode 100644 index 0000000000..b0eb79de4f --- /dev/null +++ b/ignite/cmd/completion.go @@ -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() + } + }, + } +} From 73876b9d32610bed993cbf5b0294f8c63730b2f4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 24 Jan 2024 23:59:32 +0100 Subject: [PATCH 2/2] updates --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index e33266dde8..8e04a8dcdb 100644 --- a/changelog.md +++ b/changelog.md @@ -12,7 +12,7 @@ ### Bug Fixes -- [#3896](https://github.com/ignite/cli/issues/3896) Fix `ignite completion` +- [#3905](https://github.com/ignite/cli/pull/3905) Fix `ignite completion` ## [`v28.1.1`](https://github.com/ignite/cli/releases/tag/v28.1.1)