diff options
| author | Anis Elleuch <[email protected]> | 2019-06-28 13:39:45 +0100 |
|---|---|---|
| committer | Anis Elleuch <[email protected]> | 2019-06-28 13:45:36 +0100 |
| commit | c6bcb58fc4de17d39c7b428b34659c12600263f9 (patch) | |
| tree | 028139ccfc5b79af1bc360c6743c79162ec474a5 /cmd/install/bash.go | |
| parent | 60e9d0a237999e714fb4d04727fe7ffa1b377c6e (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.go | 13 |
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) } |
