Skip to content

Commit

Permalink
update mare version
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed Feb 7, 2024
1 parent 403b4f3 commit 26d883b
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion entity/aptrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (a AptRepo) Install() error {
return err
}

out, err := marecmd.RunFormatError(marecmd.Input{Command: "dpkg --print-architecture"})
out, err := marecmd.RunFmtErr(marecmd.Input{Command: "dpkg --print-architecture"})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions entity/dnfrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type installer struct {
}

func (i installer) runMaybeSudo(cmd string) error {
_, err := marecmd.RunFormatError(marecmd.Input{Command: cmd, Sudo: !i.isRoot})
_, err := marecmd.RunFmtErr(marecmd.Input{Command: cmd, Sudo: !i.isRoot})
return err
}

Expand Down Expand Up @@ -97,7 +97,7 @@ func (i installer) configManagerInstall(repo string) error {
func (i installer) releasePackagesInstall(url []string, osId string) error {
packageList := strings.Join(url, " ")
cmd := fmt.Sprintf("rpm -E %%%s", osId)
out, err := marecmd.RunFormatError(marecmd.Input{Command: cmd})
out, err := marecmd.RunFmtErr(marecmd.Input{Command: cmd})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/alexflint/go-arg v1.4.3
github.com/antchfx/htmlquery v1.3.0
github.com/deckarep/golang-set/v2 v2.6.0
github.com/femnad/mare v0.10.0
github.com/femnad/mare v0.14.0
github.com/gabriel-vasile/mimetype v1.4.3
github.com/go-git/go-git/v5 v5.11.0
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/femnad/mare v0.10.0 h1:jO+dCqgQMSu+DYefhfod+P7USu2UndUEwWPrg4bnkr4=
github.com/femnad/mare v0.10.0/go.mod h1:6EK4dfMreuFAMMsCwX4dSo3ZUpvqPmKCGO29kpB46fU=
github.com/femnad/mare v0.14.0 h1:CYWoLKFPcZ49623QW/8bG3y+XWP7IgrANbk1j1ggZLU=
github.com/femnad/mare v0.14.0/go.mod h1:6EK4dfMreuFAMMsCwX4dSo3ZUpvqPmKCGO29kpB46fU=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
Expand Down
6 changes: 3 additions & 3 deletions internal/filecontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func getent(key, database string) (int, error) {
return defaultId, nil
}

out, err := marecmd.RunFormatError(marecmd.Input{Command: fmt.Sprintf("getent %s %s", database, key)})
out, err := marecmd.RunFmtErr(marecmd.Input{Command: fmt.Sprintf("getent %s %s", database, key)})
if err != nil {
return 0, err
}
Expand All @@ -150,7 +150,7 @@ func getStatSum(f string) (statSum, error) {
}

cmd := fmt.Sprintf("stat -c %%a %s", f)
out, err := marecmd.RunFormatError(marecmd.Input{Command: cmd, Sudo: !isRoot})
out, err := marecmd.RunFmtErr(marecmd.Input{Command: cmd, Sudo: !isRoot})
if err != nil {
if strings.HasSuffix(strings.TrimSpace(out.Stderr), statNoExistsError) {
return s, os.ErrNotExist
Expand All @@ -163,7 +163,7 @@ func getStatSum(f string) (statSum, error) {
return s, err
}

out, err = marecmd.RunFormatError(marecmd.Input{Command: fmt.Sprintf("sha256sum %s", f), Sudo: !isRoot})
out, err = marecmd.RunFmtErr(marecmd.Input{Command: fmt.Sprintf("sha256sum %s", f), Sudo: !isRoot})
if err != nil {
return s, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func MaybeRunWithSudo(cmdStr string) error {
}

cmd := marecmd.Input{Command: cmdStr, Sudo: !isRoot}
_, err = marecmd.RunFormatError(cmd)
err = marecmd.RunErrOnly(cmd)
return err
}

Expand All @@ -67,7 +67,7 @@ func MaybeRunWithSudoForPath(cmdStr, targetPath string) error {
}

cmd := marecmd.Input{Command: cmdStr, Sudo: needsSudo}
_, err = marecmd.RunFormatError(cmd)
err = marecmd.RunErrOnly(cmd)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions packages/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (i Installer) maybeRunWithSudo(cmds ...string) error {
}

cmdStr := strings.Join(cmds, " ")
_, err = marecmd.RunFormatError(marecmd.Input{
err = marecmd.RunErrOnly(marecmd.Input{
Command: cmdStr,
Sudo: !isRoot,
SudoPreserveEnv: i.Pkg.PreserveEnv(),
Expand All @@ -74,7 +74,7 @@ func (i Installer) Install(desired mapset.Set[string]) error {

func (i Installer) Version(pkg string) (string, error) {
input := marecmd.Input{Command: fmt.Sprintf("%s info %s", i.Pkg.PkgExec(), pkg)}
out, err := marecmd.RunFormatError(input)
out, err := marecmd.RunFmtErr(input)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func (i Installer) RemoteInstall(desired mapset.Set[entity.RemotePackage], s set

func (i Installer) InstalledPackages(pkg PkgManager) (mapset.Set[string], error) {
listCmd := fmt.Sprintf("%s list --installed", pkg.PkgExec())
resp, err := marecmd.RunFormatError(marecmd.Input{Command: listCmd})
resp, err := marecmd.RunFmtErr(marecmd.Input{Command: listCmd})
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions provision/flatpak.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ensureRemote(remote entity.FlatpakRemote) error {

internal.Log.Infof("Adding flatpak remote %s", remote.Name)
cmd := fmt.Sprintf("%s remote-add %s %s", flatpakExec, remote.Name, remote.Url)
_, err := marecmd.RunFormatError(marecmd.Input{Command: cmd})
err := marecmd.RunErrOnly(marecmd.Input{Command: cmd})
if err != nil {
return fmt.Errorf("error adding flatpak remote %s with URL %s: %v", remote.Name, remote.Url, err)
}
Expand Down Expand Up @@ -60,7 +60,7 @@ func ensurePkgRemote(pkg entity.FlatpakPkg, remotes []entity.FlatpakRemote) erro
}

func isInstalled(pkg entity.FlatpakPkg) (bool, error) {
out, _ := marecmd.RunFormatError(marecmd.Input{Command: fmt.Sprintf("%s info %s", flatpakExec, pkg.Name)})
out, _ := marecmd.RunFmtErr(marecmd.Input{Command: fmt.Sprintf("%s info %s", flatpakExec, pkg.Name)})
return out.Code == 0, nil
}

Expand All @@ -72,7 +72,7 @@ func ensureInstalled(pkg entity.FlatpakPkg) error {

internal.Log.Infof("Installing flatpak package %s", pkg.Name)
cmd := fmt.Sprintf("%s install %s %s -y", flatpakExec, pkg.Remote, pkg.Name)
_, err := marecmd.RunFormatError(marecmd.Input{Command: cmd})
err := marecmd.RunErrOnly(marecmd.Input{Command: cmd})
if err != nil {
return fmt.Errorf("error installing flatpak %s: %v", pkg.Name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion provision/osrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func runUpdateCmds(cmds mapset.Set[string]) []error {

cmds.Each(func(cmd string) bool {
input := marecmd.Input{Command: cmd, Sudo: !isRoot}
_, err = marecmd.RunFormatError(input)
err = marecmd.RunErrOnly(input)
errs = append(errs, err)
return false
})
Expand Down
4 changes: 2 additions & 2 deletions provision/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func pipInstall(pipBin, pkg string) error {
cmd := fmt.Sprintf("%s install %s", pipBin, pkg)
_, err := marecmd.RunFormatError(marecmd.Input{Command: cmd})
err := marecmd.RunErrOnly(marecmd.Input{Command: cmd})
if err != nil {
return err
}
Expand All @@ -37,7 +37,7 @@ func pythonInstall(pkg entity.PythonPkg, cfg entity.Config) error {
venvDir := path.Join(baseDir, name)

cmd := fmt.Sprintf("virtualenv %s", venvDir)
_, err := marecmd.RunFormatError(marecmd.Input{Command: cmd})
err := marecmd.RunErrOnly(marecmd.Input{Command: cmd})
if err != nil {
internal.Log.Errorf("error creating virtualenv for package %s: %v", name, err)
return err
Expand Down
2 changes: 1 addition & 1 deletion provision/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func ensureRelease(release entity.Release, s settings.Settings) error {
internal.Log.Debugf("Running command %s under path %s", cmd, pwd)
}

_, err = marecmd.RunFormatError(marecmd.Input{Command: cmd, Pwd: pwd, Shell: true})
err = marecmd.RunErrOnly(marecmd.Input{Command: cmd, Pwd: pwd, Shell: true})
if err != nil {
internal.Log.Errorf("error running post download command: %v", err)
return err
Expand Down
8 changes: 4 additions & 4 deletions provision/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func writeTmpl(s entity.Service) (string, error) {

func runSystemctlCmd(cmd string, service entity.Service) error {
internal.Log.Debugf("running systemctl command %s for service %s", cmd, service.Name)
_, err := marecmd.RunFormatError(marecmd.Input{Command: cmd, Sudo: service.System})
err := marecmd.RunErrOnly(marecmd.Input{Command: cmd, Sudo: service.System})
return err
}

Expand All @@ -104,7 +104,7 @@ func writeServiceFile(file, content string) (bool, error) {

func maybeRestart(s entity.Service) error {
cmd := systemctlCmd("is-active", s.Name, !s.System)
out, err := marecmd.RunFormatError(marecmd.Input{Command: cmd})
out, err := marecmd.RunFmtErr(marecmd.Input{Command: cmd})
if err != nil {
if strings.TrimSpace(out.Stdout) == "inactive" {
return nil
Expand All @@ -115,7 +115,7 @@ func maybeRestart(s entity.Service) error {
internal.Log.Debugf("restarting active service %s due to service file content changes", s.Name)

cmd = systemctlCmd("restart", s.Name, !s.System)
return marecmd.RunNoOutput(marecmd.Input{Command: cmd, Sudo: s.System})
return marecmd.RunErrOnly(marecmd.Input{Command: cmd, Sudo: s.System})
}

func getServiceExec(serviceFile string) (string, error) {
Expand Down Expand Up @@ -269,7 +269,7 @@ func ensureServiceState(s entity.Service, actionStr string) error {
}

// Don't need sudo for check actions, so don't use runSystemctlCmd
resp, _ := marecmd.RunFormatError(marecmd.Input{Command: checkCmd})
resp, _ := marecmd.RunFmtErr(marecmd.Input{Command: checkCmd})
if negated && resp.Code != 0 {
return nil
} else if !negated && resp.Code == 0 {
Expand Down
2 changes: 1 addition & 1 deletion provision/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func isSnapInstalled(snap entity.Snap) bool {
out, _ := marecmd.RunFormatError(marecmd.Input{Command: fmt.Sprintf("snap list %s", snap.Name)})
out, _ := marecmd.RunFmtErr(marecmd.Input{Command: fmt.Sprintf("snap list %s", snap.Name)})
return out.Code == 0
}

Expand Down
4 changes: 2 additions & 2 deletions provision/useringroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func addUserToGroup(user, group string) error {

internal.Log.Infof("Adding user %s to group %s", user, group)
usermod := fmt.Sprintf("usermod -aG %s %s", group, user)
_, err = marecmd.RunFormatError(marecmd.Input{Command: usermod, Sudo: !isRoot})
err = marecmd.RunErrOnly(marecmd.Input{Command: usermod, Sudo: !isRoot})
if err != nil {
return err
}
Expand All @@ -41,7 +41,7 @@ func groupAdd(group entity.Group) error {
cmd += " " + group.Name

internal.Log.Infof("Creating group %s", group.Name)
_, err = marecmd.RunFormatError(marecmd.Input{Command: cmd, Sudo: !isRoot})
err = marecmd.RunErrOnly(marecmd.Input{Command: cmd, Sudo: !isRoot})
return err
}

Expand Down
7 changes: 1 addition & 6 deletions run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,5 @@ func amendEnv(s settings.Settings, input marecmd.Input) marecmd.Input {

func Cmd(s settings.Settings, input marecmd.Input) (marecmd.Output, error) {
input = amendEnv(s, input)
return marecmd.RunFormatError(input)
}

func CmdNoOutput(s settings.Settings, input marecmd.Input) error {
input = amendEnv(s, input)
return marecmd.RunNoOutput(input)
return marecmd.RunFmtErr(input)
}

0 comments on commit 26d883b

Please sign in to comment.