diff options
| author | Eyal Posener <[email protected]> | 2017-05-06 22:06:49 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-06 22:15:15 +0300 |
| commit | 703dd6ebc30f7c6f5a5c02e07a307e0e34d9c2c2 (patch) | |
| tree | 6efd5f6d1205eb6188193c86f5dd1e256b8996c5 /cmd/install/install.go | |
| parent | 9963a854946be0603f9e79ccba0a8b2688b20053 (diff) | |
improve docs
Diffstat (limited to 'cmd/install/install.go')
| -rw-r--r-- | cmd/install/install.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/cmd/install/install.go b/cmd/install/install.go new file mode 100644 index 0000000..cef11f0 --- /dev/null +++ b/cmd/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) +} |
