diff options
| author | Eyal Posener <[email protected]> | 2017-05-06 18:55:54 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-06 18:55:54 +0300 |
| commit | 4f47fe9246e715f11272d6323343a12797d4d13f (patch) | |
| tree | 65eb8cd82bbb5da33c548b5510f91f8017b04330 /install/install.go | |
| parent | d33bac720bcaf13a5ee9f6f165293183d2e3e24d (diff) | |
Add easy way to install the bash completion
Diffstat (limited to 'install/install.go')
| -rw-r--r-- | install/install.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/install/install.go b/install/install.go new file mode 100644 index 0000000..cef11f0 --- /dev/null +++ b/install/install.go @@ -0,0 +1,43 @@ +package install + +import ( + "os" + "path/filepath" +) + +type installer interface { + Install(cmd, bin string) error + Uninstall(cmd, bin string) error +} + +func Install(cmd string, asRoot bool) error { + bin, err := getBinaryPath() + if err != nil { + return err + } + return getInstaller(asRoot).Install(cmd, bin) +} + +func Uninstall(cmd string, asRoot bool) error { + bin, err := getBinaryPath() + if err != nil { + return err + } + return getInstaller(asRoot).Uninstall(cmd, bin) +} + +func getInstaller(asRoot bool) installer { + if asRoot { + return root{} + } else { + return home{} + } +} + +func getBinaryPath() (string, error) { + bin, err := os.Executable() + if err != nil { + return "", err + } + return filepath.Abs(bin) +} |
