From 7d8039ca5e9cdb99c9c6d0a96ed6a20dbff19c41 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 4 Aug 2021 13:33:58 -0400 Subject: [PATCH] Use Cobra to provide all the completions Cobra provides support for flag and command completion. By using helm's dynamic completion for plugins, we can use Cobra's support instead of coding things ourselves. Signed-off-by: Marc Khouzam --- .goreleaser.yml | 2 +- cmd/move_config.go | 3 ++- completion.yaml | 35 ----------------------------------- plugin.complete | 9 +++++++++ plugin.yaml | 2 +- scripts/install_plugin.sh | 2 +- 6 files changed, 14 insertions(+), 39 deletions(-) delete mode 100644 completion.yaml create mode 100755 plugin.complete diff --git a/.goreleaser.yml b/.goreleaser.yml index d26ed18..5ce4795 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -17,7 +17,7 @@ archives: - README.md - LICENSE - plugin.yaml - - completion.yaml + - plugin.complete - scripts/install_plugin.sh checksum: name_template: 'checksums.txt' diff --git a/cmd/move_config.go b/cmd/move_config.go index 944f947..225a107 100644 --- a/cmd/move_config.go +++ b/cmd/move_config.go @@ -36,7 +36,8 @@ func newMoveConfigCmd(out io.Writer) *cobra.Command { } return nil }, - RunE: runMove, + ValidArgs: []string{"config"}, + RunE: runMove, } flags := cmd.Flags() diff --git a/completion.yaml b/completion.yaml deleted file mode 100644 index c8fae83..0000000 --- a/completion.yaml +++ /dev/null @@ -1,35 +0,0 @@ -commands: -- name: cleanup - flags: - - config-cleanup - - dry-run - - l - - label - - name - - release-cleanup - - s - - release-storage - - skip-confirmation - - tiller-cleanup - - t - - tiller-ns - - tiller-out-cluster -- name: convert - flags: - - delete-v2-releases - - dry-run - - ignore-already-migrated - - l - - label - - s - - release-storage - - release-versions-max - - t - - tiller-ns - - tiller-out-cluster -- name: move - commands: - - name: config - flags: - - dry-run - - skip-confirmation diff --git a/plugin.complete b/plugin.complete new file mode 100755 index 0000000..881e288 --- /dev/null +++ b/plugin.complete @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# It is important to quote the $@ variable since the last parameter +# could be empty, which indicates that the prefix to complete is empty. +# For example: +# helm 2to3 convert +# compared to +# helm 2to3 convert ngi +$HELM_PLUGIN_DIR/bin/2to3 __complete "$@" diff --git a/plugin.yaml b/plugin.yaml index 3920098..d144bad 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: "2to3" -version: "0.9.0" +version: "0.9.1" usage: "migrate and cleanup Helm v2 configuration and releases in-place to Helm v3" description: "migrate and cleanup Helm v2 configuration and releases in-place to Helm v3" command: "$HELM_PLUGIN_DIR/bin/2to3" diff --git a/scripts/install_plugin.sh b/scripts/install_plugin.sh index 16cf730..2b56da5 100755 --- a/scripts/install_plugin.sh +++ b/scripts/install_plugin.sh @@ -41,7 +41,7 @@ fi tar xzf "releases/v${version}.tar.gz" -C "releases/v${version}" mv "releases/v${version}/2to3" "bin/2to3" || \ mv "releases/v${version}/2to3.exe" "bin/2to3" -mv "releases/v${version}/completion.yaml" . +mv "releases/v${version}/plugin.complete" . mv "releases/v${version}/plugin.yaml" . mv "releases/v${version}/README.md" . mv "releases/v${version}/LICENSE" .