diff options
| author | Eyal Posener <[email protected]> | 2017-05-06 22:21:03 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-05-06 22:21:03 +0300 |
| commit | c26ef096c7990a5ae97b503545fd76ff6df388d6 (patch) | |
| tree | d0180b667269b985d15520f3b2e1aafc9292af6e /cmd/install/install.go | |
| parent | 2b6aed2b1e974a733c0dc614a9617c33a54c208c (diff) | |
| parent | 404634e843081e7010260bd95006b84d6c40a8fd (diff) | |
Merge pull request #4 from posener/doc
Doc
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) +} |
