summaryrefslogtreecommitdiff
path: root/cmd/install/install.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-08 07:32:13 +0300
committerEyal Posener <[email protected]>2017-05-08 07:32:13 +0300
commit5db452a63f1b8ff0319f08986a4a04324647738f (patch)
treeadcd52253a99c5faf7817a6d2e415430f121d9c7 /cmd/install/install.go
parentb2791b736089134d6914c4d4362fbcdeadf1cdab (diff)
Install fixups
- remove root installation - install according to shell type Closes #7
Diffstat (limited to 'cmd/install/install.go')
-rw-r--r--cmd/install/install.go45
1 files changed, 33 insertions, 12 deletions
diff --git a/cmd/install/install.go b/cmd/install/install.go
index c20e11a..bb44ad8 100644
--- a/cmd/install/install.go
+++ b/cmd/install/install.go
@@ -1,6 +1,8 @@
package install
import (
+ "errors"
+ "fmt"
"os"
"path/filepath"
)
@@ -12,33 +14,47 @@ type installer interface {
// Install complete command given:
// cmd: is the command name
-// asRoot: if true the completion will be installed in /etc/bash_complete.d
-// otherwise the complete command will be added to the ~/.bashrc file.
-func Install(cmd string, asRoot bool) error {
+func Install(cmd string) error {
+ shell := shellType()
+ if shell == "" {
+ return errors.New("must install through a terminatl")
+ }
+ i := getInstaller(shell)
+ if i == nil {
+ return fmt.Errorf("shell %s not supported", shell)
+ }
bin, err := getBinaryPath()
if err != nil {
return err
}
- return getInstaller(asRoot).Install(cmd, bin)
+ return i.Install(cmd, bin)
}
// Uninstall complete command given:
// cmd: is the command name
-// asRoot: if true the completion will be removed from /etc/bash_complete.d
-// otherwise the complete command will be removed from the ~/.bashrc file.
-func Uninstall(cmd string, asRoot bool) error {
+func Uninstall(cmd string) error {
+ shell := shellType()
+ if shell == "" {
+ return errors.New("must uninstall through a terminatl")
+ }
+ i := getInstaller(shell)
+ if i == nil {
+ return fmt.Errorf("shell %s not supported", shell)
+ }
bin, err := getBinaryPath()
if err != nil {
return err
}
- return getInstaller(asRoot).Uninstall(cmd, bin)
+ return i.Uninstall(cmd, bin)
}
-func getInstaller(asRoot bool) installer {
- if asRoot {
- return root{}
+func getInstaller(shell string) installer {
+ switch shell {
+ case "bash":
+ return bash{}
+ default:
+ return nil
}
- return home{}
}
func getBinaryPath() (string, error) {
@@ -48,3 +64,8 @@ func getBinaryPath() (string, error) {
}
return filepath.Abs(bin)
}
+
+func shellType() string {
+ shell := os.Getenv("SHELL")
+ return filepath.Base(shell)
+}