From c6bcb58fc4de17d39c7b428b34659c12600263f9 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Fri, 28 Jun 2019 13:39:45 +0100 Subject: 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. --- cmd/install/bash.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'cmd/install/bash.go') 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) } -- cgit v1.2.3