feat(packages): add nala package manager

This commit is contained in:
DataHearth 2022-07-20 13:33:04 +02:00
parent 224754870d
commit 8051912b35
No known key found for this signature in database
GPG Key ID: E88FD356ACC5F3C4
3 changed files with 22 additions and 1 deletions

View File

@ -69,9 +69,11 @@ func init() {
loadCmd.Flags().Bool("disable-files", false, "files will be ignored")
loadCmd.Flags().Bool("disable-folders", false, "folders will be ignored")
loadCmd.Flags().Bool("pkgs", false, "packages will be installed")
loadCmd.Flags().StringSlice("exclude-pkg-managers", []string{}, "package managers to exclude (comma separated)")
viper.BindPFlag("load-disable-files", loadCmd.Flags().Lookup("disable-files"))
viper.BindPFlag("load-disable-folders", loadCmd.Flags().Lookup("disable-folders"))
viper.BindPFlag("load-enable-pkgs", loadCmd.Flags().Lookup("pkgs"))
viper.BindPFlag("exclude-pkg-managers", loadCmd.Flags().Lookup("exclude-pkg-managers"))
saveCmd.Flags().Bool("disable-files", false, "files will be ignored")
saveCmd.Flags().Bool("disable-folders", false, "folders will be ignored")

View File

@ -43,4 +43,5 @@ type PkgManagers struct {
Pip []string `mapstructure:"pip" yaml:"pip"`
Npm []string `mapstructure:"npm" yaml:"npm"`
Go []string `mapstructure:"go" yaml:"go"`
Nala []string `mapstructure:"nala" yaml:"nala"`
}

View File

@ -17,9 +17,18 @@ import (
// InstallPackages install all packages from the configuration file by installation order
func InstallPackages(c configuration.PkgManagers) error {
color.Blue("\n# Installing packages")
pkgManagers := map[string]bool{}
for _, pkgManager := range viper.GetStringSlice("exclude-pkg-managers") {
pkgManagers[pkgManager] = true
}
for _, pkgManager := range c.InstallationOrder {
color.Blue("## Installing %s packages", pkgManager)
if _, ok := pkgManagers[pkgManager]; ok {
color.Blue("Skipping %s packages", pkgManager)
fmt.Println()
continue
}
var pkgs []string
switch pkgManager {
@ -35,6 +44,8 @@ func InstallPackages(c configuration.PkgManagers) error {
pkgs = c.Pip
case "go":
pkgs = c.Go
case "nala":
pkgs = c.Nala
default:
PrintError("package manager not supported: %s\n", pkgManager)
continue
@ -64,7 +75,14 @@ func InstallPackages(c configuration.PkgManagers) error {
continue
}
cmd := exec.Command(pkgManager, "install")
var cmd *exec.Cmd
// * package managers requiring sudo permission
if pkgManager == "apt" || pkgManager == "nala" {
cmd = exec.Command("sudo", pkgManager, "install", "-y")
} else {
cmd = exec.Command(pkgManager, "install")
}
for _, pkg := range pkgs {
if strings.Contains(pkg, " ") {
cmd.Args = append(cmd.Args, strings.Split(pkg, " ")...)