AllPac/pkg/packagemanager/pacman.go
VetheonGames 50af1b9613 Major update 4
This should be the final code update before we start testing things.
I think all the code is now in place to have the program function, barring any bugs in my code.

So, with that said, here's the changelog:

global changes:
```
- implement logger.go across the whole program
```

changes to main.go:
```
- add an import for strings
- implement the roughed in handling functions
```

changes to logger.go:
```
- create this little helper package to just handle all our logging nice and gracefully
```

changes to all_updater.go:
```
- basically completely redone. Accomplishes the same thing, just in a different, more efficient way.
```

changes to aur.go:
```
- add a function to clear the AllPac build cache for aur
```

changes to install.go:
```
- removed a duplicate function, set install.go to call the right one
```

changes to pacman.go:
```
- removed GetVersionFromPacman function (it shouldn't be here, it should be in search.go)
```

changes to search.go:
```
- add functions for getting info from, and parsing output from Snap, Pacman, Flatpak, and aur
```
2024-01-04 19:17:43 -07:00

38 lines
1.3 KiB
Go

package packagemanager
// This package is responsible for handling updating and uninstalling pacman packages
import (
"fmt"
"os/exec"
"pixelridgesoftworks.com/AllPac/pkg/logger"
)
// UpdatePacmanPackages updates specified Pacman packages or all if no specific package is provided
func UpdatePacmanPackages(packageNames ...string) error {
var cmd *exec.Cmd
if len(packageNames) == 0 {
cmd = exec.Command("sudo", "pacman", "-Syu")
} else {
args := append([]string{"sudo", "pacman", "-S", "--noconfirm"}, packageNames...)
cmd = exec.Command(args[0], args[1:]...)
}
if output, err := cmd.CombinedOutput(); err != nil {
logger.Errorf("error updating Pacman packages: %s, %v", string(output), err)
return fmt.Errorf("error updating Pacman packages: %s, %v", string(output), err)
}
return nil
}
// UninstallPacmanPackage uninstalls a specified Pacman package
func UninstallPacmanPackage(packageName string) error {
cmd := exec.Command("sudo", "pacman", "-Rns", "--noconfirm", packageName)
if output, err := cmd.CombinedOutput(); err != nil {
logger.Errorf("error uninstalling Pacman package: %s, %v", output, err)
return fmt.Errorf("error uninstalling Pacman package: %s, %v", output, err)
}
return nil
}