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/zsh.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/zsh.go')
| -rw-r--r-- | cmd/install/zsh.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/cmd/install/zsh.go b/cmd/install/zsh.go index a625f53..29950ab 100644 --- a/cmd/install/zsh.go +++ b/cmd/install/zsh.go @@ -11,12 +11,17 @@ type zsh struct { rc string } -func (z zsh) Install(cmd, bin string) error { +func (z zsh) IsInstalled(cmd, bin string) bool { completeCmd := z.cmd(cmd, bin) - if lineInFile(z.rc, completeCmd) { + return lineInFile(z.rc, completeCmd) +} + +func (z zsh) Install(cmd, bin string) error { + if z.IsInstalled(cmd, bin) { return fmt.Errorf("already installed in %s", z.rc) } + completeCmd := z.cmd(cmd, bin) bashCompInit := "autoload -U +X bashcompinit && bashcompinit" if !lineInFile(z.rc, bashCompInit) { completeCmd = bashCompInit + "\n" + completeCmd @@ -26,11 +31,11 @@ func (z zsh) Install(cmd, bin string) error { } func (z zsh) Uninstall(cmd, bin string) error { - completeCmd := z.cmd(cmd, bin) - if !lineInFile(z.rc, completeCmd) { + if !z.IsInstalled(cmd, bin) { return fmt.Errorf("does not installed in %s", z.rc) } + completeCmd := z.cmd(cmd, bin) return removeFromFile(z.rc, completeCmd) } |
