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

Add autocompletion generation for more shells #337

Merged
merged 1 commit into from
Jun 2, 2021
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
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ brews:
bin.install "exo"
man1.install Dir["manpage/exo*.1"]
bash_completion.install "contrib/completion/bash/exo"
fish_completion.install "contrib/completion/fish/exo"
zsh_completion.install "contrib/completion/zsh/exo"
falzm marked this conversation as resolved.
Show resolved Hide resolved

dockers:
- goos: linux
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ manpages: manpage

.PHONY: completions
completions:
mkdir -p contrib/completion/bash
$(GO) run -mod vendor completion/main.go
mv bash_completion contrib/completion/bash/exo
mkdir -p contrib/completion/{bash,fish,powershell,zsh}
$(GO) run -mod vendor completion/main.go bash ; mv bash_completion contrib/completion/bash/exo
$(GO) run -mod vendor completion/main.go fish ; mv fish_completion contrib/completion/fish/exo
$(GO) run -mod vendor completion/main.go powershell ; mv powershell_completion contrib/completion/powershell/exo
$(GO) run -mod vendor completion/main.go zsh ; mv zsh_completion contrib/completion/zsh/exo
falzm marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: clean
clean::
Expand Down
25 changes: 24 additions & 1 deletion completion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,35 @@ package main

import (
"log"
"os"

"github.com/exoscale/cli/cmd"
)

func main() {
if err := cmd.RootCmd.GenBashCompletionFile("bash_completion"); err != nil {
if len(os.Args) != 2 {
log.Fatalf("usage: %s (bash|fish|powershell|zsh)", os.Args[0])
}

var err error
switch os.Args[1] {
case "bash":
err = cmd.RootCmd.GenBashCompletionFile("bash_completion")

case "fish":
err = cmd.RootCmd.GenFishCompletionFile("fish_completion", true)

case "powershell":
err = cmd.RootCmd.GenPowerShellCompletionFile("powershell_completion")

case "zsh":
err = cmd.RootCmd.GenZshCompletionFile("zsh_completion")

default:
log.Fatalf("unsupported shell %q", os.Args[1])
}

if err != nil {
log.Fatal(err)
}
}