mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-29 03:45:27 +01:00
bash completions: hidden subcommand + integrate into Makefile
This commit is contained in:
parent
ebf209427a
commit
d7f3fb93ae
7
Makefile
7
Makefile
@ -18,6 +18,8 @@ GO_LDFLAGS := "-X github.com/zrepl/zrepl/cmd.zreplVersion=$(ZREPL_VERSION)"
|
|||||||
|
|
||||||
GO_BUILD := go build -ldflags $(GO_LDFLAGS)
|
GO_BUILD := go build -ldflags $(GO_LDFLAGS)
|
||||||
|
|
||||||
|
THIS_PLATFORM_RELEASE_BIN := $(shell bash -c 'source <(go env) && echo "zrepl-$${GOOS}-$${GOARCH}"' )
|
||||||
|
|
||||||
vendordeps:
|
vendordeps:
|
||||||
dep ensure -v -vendor-only
|
dep ensure -v -vendor-only
|
||||||
|
|
||||||
@ -57,6 +59,9 @@ $(ARTIFACTDIR):
|
|||||||
$(ARTIFACTDIR)/docs: $(ARTIFACTDIR)
|
$(ARTIFACTDIR)/docs: $(ARTIFACTDIR)
|
||||||
mkdir -p "$@"
|
mkdir -p "$@"
|
||||||
|
|
||||||
|
$(ARTIFACTDIR)/bash_completion: release-bins
|
||||||
|
artifacts/$(THIS_PLATFORM_RELEASE_BIN) bashcomp "$@"
|
||||||
|
|
||||||
docs: $(ARTIFACTDIR)/docs
|
docs: $(ARTIFACTDIR)/docs
|
||||||
make -C docs \
|
make -C docs \
|
||||||
html \
|
html \
|
||||||
@ -72,7 +77,7 @@ release-bins: $(ARTIFACTDIR) vet test
|
|||||||
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl-linux-amd64"
|
GOOS=linux GOARCH=amd64 $(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl-linux-amd64"
|
||||||
GOOS=freebsd GOARCH=amd64 $(GO_BUILD) -o "$(ARTIFACTDIR)/zrepl-freebsd-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
|
clean: docs-clean
|
||||||
|
29
cmd/bashcomp.go
Normal file
29
cmd/bashcomp.go
Normal file
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user