From a5a7c1dcf358bfdb7fca3065c1b0511dfbf4f8ec Mon Sep 17 00:00:00 2001 From: LEI Date: Thu, 13 Sep 2018 17:59:45 +0200 Subject: [PATCH] pkg --- internal/dot/pkg.go | 4 ++-- internal/pkg/pkg.go | 11 +++++------ internal/pkg/pkg_apt.go | 6 +++--- internal/pkg/pkg_pip.go | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/internal/dot/pkg.go b/internal/dot/pkg.go index 3b9e8c1..b37dd7c 100644 --- a/internal/dot/pkg.go +++ b/internal/dot/pkg.go @@ -41,8 +41,8 @@ func (t *Pkg) String() string { fmt.Fprintf(os.Stderr, "pkg: m.BuildOptions errored with: %s\n", err) return "" } - opts = m.ParseOpts(opts) - return fmt.Sprintf("%s %s", m.Bin, shell.FormatArgs(opts)) + bin, opts := m.ParseOpts(opts) + return fmt.Sprintf("%s %s", bin, shell.FormatArgs(opts)) } // Init task diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index 0e297d1..daa17d2 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -180,15 +180,14 @@ func (m *Pm) GetAction(name string, input ...string) (string, error) { } // ParseOpts replaces bin with sudo if needed and prepend options with it. -func (m *Pm) ParseOpts(opts []string) []string { +func (m *Pm) ParseOpts(opts []string) (string, []string) { bin := m.Bin // Switch binary for sudo if m.Sudo && bin != "sudo" && !isRoot() { opts = append([]string{bin}, opts...) bin = "sudo" } - m.Bin = bin - return opts + return bin, opts } func pkgOnly(input []string) []string { @@ -281,7 +280,7 @@ func (m *Pm) Exec(args ...string) error { } func (m *Pm) exec(args ...string) error { - args = m.ParseOpts(args) + bin, args := m.ParseOpts(args) if DryRun { if len(m.DryRunOpts) == 0 { return nil @@ -293,10 +292,10 @@ func (m *Pm) exec(args ...string) error { if m.Shell != "" { s := shell.Get() // if Verbose { fmt.Println("Using shell:", s) } - c := fmt.Sprintf("%s %s", m.Bin, shell.FormatArgs(args)) + c := fmt.Sprintf("%s %s", bin, shell.FormatArgs(args)) cmd = exec.Command(s, "-c", c) } else { - cmd = exec.Command(m.Bin, args...) + cmd = exec.Command(bin, args...) } return execWithEnv(m.Env, cmd) } diff --git a/internal/pkg/pkg_apt.go b/internal/pkg/pkg_apt.go index 4754af0..51e8b2d 100644 --- a/internal/pkg/pkg_apt.go +++ b/internal/pkg/pkg_apt.go @@ -5,7 +5,7 @@ import ( "os/exec" ) -var aptGet *Pm +var aptGet = &Pm{} // https://manpages.debian.org/stretch/apt/apt-get.8.en.html func init() { @@ -56,10 +56,10 @@ func init() { } // https://wiki.termux.com/wiki/Package_Management -var termux *Pm +var termux = &Pm{} func init() { - termux = aptGet + *termux = *aptGet termux.Sudo = false termux.Bin = "pkg" termux.Install = "install" diff --git a/internal/pkg/pkg_pip.go b/internal/pkg/pkg_pip.go index 6279a6e..45c4cf1 100644 --- a/internal/pkg/pkg_pip.go +++ b/internal/pkg/pkg_pip.go @@ -5,7 +5,7 @@ import ( "runtime" ) -var pip, pip2, pip3 *Pm +var pip, pip2, pip3 = &Pm{}, &Pm{}, &Pm{} // https://pip.pypa.io/en/stable/reference func init() { @@ -50,7 +50,7 @@ func init() { } // windows: python -m pip ... - pip2 = pip + *pip2 = *pip pip2.Bin = "pip2" // FIXME: python2 -c 'import neovim' did not work until // pip2 uninstall neovim && pip2 install neovim @@ -62,7 +62,7 @@ func init() { return err == nil, nil } - pip3 = pip + *pip3 = *pip pip3.Bin = "pip3" pip3.Has = func(pkgs []string) (bool, error) { opts := []string{"show"}