summaryrefslogtreecommitdiff
path: root/cmd/install/bash.go
diff options
context:
space:
mode:
authorAnis Elleuch <[email protected]>2019-06-28 13:39:45 +0100
committerAnis Elleuch <[email protected]>2019-06-28 13:45:36 +0100
commitc6bcb58fc4de17d39c7b428b34659c12600263f9 (patch)
tree028139ccfc5b79af1bc360c6743c79162ec474a5 /cmd/install/bash.go
parent60e9d0a237999e714fb4d04727fe7ffa1b377c6e (diff)
Add IsInstalled API to installer interface
`IsInstalled(cmd, bin string) bool` will help tools using this library to show a prompt to users asking if they would like to have completion enabled.
Diffstat (limited to 'cmd/install/bash.go')
-rw-r--r--cmd/install/bash.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/cmd/install/bash.go b/cmd/install/bash.go
index a287f99..17c64de 100644
--- a/cmd/install/bash.go
+++ b/cmd/install/bash.go
@@ -10,20 +10,25 @@ type bash struct {
rc string
}
-func (b bash) Install(cmd, bin string) error {
+func (b bash) IsInstalled(cmd, bin string) bool {
completeCmd := b.cmd(cmd, bin)
- if lineInFile(b.rc, completeCmd) {
+ return lineInFile(b.rc, completeCmd)
+}
+
+func (b bash) Install(cmd, bin string) error {
+ if b.IsInstalled(cmd, bin) {
return fmt.Errorf("already installed in %s", b.rc)
}
+ completeCmd := b.cmd(cmd, bin)
return appendToFile(b.rc, completeCmd)
}
func (b bash) Uninstall(cmd, bin string) error {
- completeCmd := b.cmd(cmd, bin)
- if !lineInFile(b.rc, completeCmd) {
+ if !b.IsInstalled(cmd, bin) {
return fmt.Errorf("does not installed in %s", b.rc)
}
+ completeCmd := b.cmd(cmd, bin)
return removeFromFile(b.rc, completeCmd)
}