Skip to content

Commit

Permalink
pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
LEI committed Sep 13, 2018
1 parent 4c81d69 commit a5a7c1d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions internal/dot/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (t *Pkg) String() string {
fmt.Fprintf(os.Stderr, "pkg: m.BuildOptions errored with: %s\n", err)
return "<err>"
}
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
Expand Down
11 changes: 5 additions & 6 deletions internal/pkg/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/pkg_apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/pkg_pip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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"}
Expand Down

0 comments on commit a5a7c1d

Please sign in to comment.