diff --git a/Makefile b/Makefile index 3fa14ca..d1beb02 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,8 @@ GO_LDFLAGS := "-X github.com/zrepl/zrepl/cmd.zreplVersion=$(ZREPL_VERSION)" GO_BUILD := go build -ldflags $(GO_LDFLAGS) +THIS_PLATFORM_RELEASE_BIN := $(shell bash -c 'source <(go env) && echo "zrepl-$${GOOS}-$${GOARCH}"' ) + vendordeps: dep ensure -v -vendor-only @@ -57,6 +59,9 @@ $(ARTIFACTDIR): $(ARTIFACTDIR)/docs: $(ARTIFACTDIR) mkdir -p "$@" +$(ARTIFACTDIR)/bash_completion: release-bins + artifacts/$(THIS_PLATFORM_RELEASE_BIN) bashcomp "$@" + docs: $(ARTIFACTDIR)/docs make -C docs \ html \ @@ -72,7 +77,7 @@ release-bins: $(ARTIFACTDIR) vet test GOOS=linux GOARCH=amd64 $(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl-linux-amd64" GOOS=freebsd GOARCH=amd64 $(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl-freebsd-amd64" -release: release-bins docs +release: release-bins docs $(ARTIFACTDIR)/bash_completion clean: docs-clean diff --git a/cmd/bashcomp.go b/cmd/bashcomp.go new file mode 100644 index 0000000..3b39252 --- /dev/null +++ b/cmd/bashcomp.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + "os" +) + +var bashcompCmd = &cobra.Command{ + Use: "bashcomp path/to/out/file", + Short: "generate bash completions", + Run: func(cmd *cobra.Command, args []string) { + if len(args) != 1 { + fmt.Fprintf(os.Stderr, "specify exactly one positional agument\n") + cmd.Usage() + os.Exit(1) + } + if err := RootCmd.GenBashCompletionFile(args[0]); err != nil { + fmt.Fprintf(os.Stderr, "error generating bash completion: %s", err) + os.Exit(1) + } + }, + Hidden: true, +} + +func init() { + RootCmd.AddCommand(bashcompCmd) +}