From 1d1fab22e561d7a7a6f70957f30a289ecd6ea161 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Tue, 18 Jul 2023 16:21:24 +0200 Subject: [PATCH] feat: add auto complete --- components/fctl/.gitignore | 1 + components/fctl/.goreleaser.yml | 11 +++++++++++ components/fctl/scripts/completions.sh | 9 +++++++++ 3 files changed, 21 insertions(+) create mode 100755 components/fctl/scripts/completions.sh diff --git a/components/fctl/.gitignore b/components/fctl/.gitignore index fbb217c71a..a557a39ae4 100644 --- a/components/fctl/.gitignore +++ b/components/fctl/.gitignore @@ -5,3 +5,4 @@ dist/ autocomplete.* fctl coverage.* +completions diff --git a/components/fctl/.goreleaser.yml b/components/fctl/.goreleaser.yml index 4cce4851f4..ea64af0bc5 100644 --- a/components/fctl/.goreleaser.yml +++ b/components/fctl/.goreleaser.yml @@ -1,3 +1,5 @@ +# source about auto completion = https://carlosbecker.com/posts/golang-completions-cobra/ + project_name: fctl includes: - from_file: @@ -25,6 +27,10 @@ builds: - amd64 - arm64 +before: + hooks: + - ./scripts/completions.sh + archives: - id: "{{.ProjectName}}" builds: @@ -34,6 +40,8 @@ archives: format: zip format: tar.gz name_template: "{{.ProjectName}}_{{.Os}}-{{.Arch}}" + files: + - completions/* brews: - tap: @@ -47,3 +55,6 @@ brews: system "#{bin}/fctl version" install: | bin.install "fctl" + bash_completion.install "completions/fctl.bash" => "fctl" + zsh_completion.install "completions/fctl.zsh" => "_fctl" + fish_completion.install "completions/fctl.fish" diff --git a/components/fctl/scripts/completions.sh b/components/fctl/scripts/completions.sh new file mode 100755 index 0000000000..be5f23688e --- /dev/null +++ b/components/fctl/scripts/completions.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# scripts/completions.sh +set -e +rm -rf completions +mkdir completions + +for sh in bash zsh fish; do + go run main.go completion "$sh" >"completions/fctl.$sh" +done