aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/posener/complete/cmd/install/bash.go
diff options
context:
space:
mode:
authorAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
committerAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
commit15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch)
tree255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/posener/complete/cmd/install/bash.go
parent07971ca38143c5faf951d152fba370ddcbe26ad5 (diff)
downloadterraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/posener/complete/cmd/install/bash.go')
-rw-r--r--vendor/github.com/posener/complete/cmd/install/bash.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/github.com/posener/complete/cmd/install/bash.go b/vendor/github.com/posener/complete/cmd/install/bash.go
new file mode 100644
index 0000000..a287f99
--- /dev/null
+++ b/vendor/github.com/posener/complete/cmd/install/bash.go
@@ -0,0 +1,32 @@
1package install
2
3import "fmt"
4
5// (un)install in bash
6// basically adds/remove from .bashrc:
7//
8// complete -C </path/to/completion/command> <command>
9type bash struct {
10 rc string
11}
12
13func (b bash) Install(cmd, bin string) error {
14 completeCmd := b.cmd(cmd, bin)
15 if lineInFile(b.rc, completeCmd) {
16 return fmt.Errorf("already installed in %s", b.rc)
17 }
18 return appendToFile(b.rc, completeCmd)
19}
20
21func (b bash) Uninstall(cmd, bin string) error {
22 completeCmd := b.cmd(cmd, bin)
23 if !lineInFile(b.rc, completeCmd) {
24 return fmt.Errorf("does not installed in %s", b.rc)
25 }
26
27 return removeFromFile(b.rc, completeCmd)
28}
29
30func (bash) cmd(cmd, bin string) string {
31 return fmt.Sprintf("complete -C %s %s", bin, cmd)
32}