feat(packages): add nala package manager
This commit is contained in:
parent
224754870d
commit
8051912b35
|
@ -69,9 +69,11 @@ func init() {
|
||||||
loadCmd.Flags().Bool("disable-files", false, "files will be ignored")
|
loadCmd.Flags().Bool("disable-files", false, "files will be ignored")
|
||||||
loadCmd.Flags().Bool("disable-folders", false, "folders will be ignored")
|
loadCmd.Flags().Bool("disable-folders", false, "folders will be ignored")
|
||||||
loadCmd.Flags().Bool("pkgs", false, "packages will be installed")
|
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-files", loadCmd.Flags().Lookup("disable-files"))
|
||||||
viper.BindPFlag("load-disable-folders", loadCmd.Flags().Lookup("disable-folders"))
|
viper.BindPFlag("load-disable-folders", loadCmd.Flags().Lookup("disable-folders"))
|
||||||
viper.BindPFlag("load-enable-pkgs", loadCmd.Flags().Lookup("pkgs"))
|
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-files", false, "files will be ignored")
|
||||||
saveCmd.Flags().Bool("disable-folders", false, "folders will be ignored")
|
saveCmd.Flags().Bool("disable-folders", false, "folders will be ignored")
|
||||||
|
|
|
@ -43,4 +43,5 @@ type PkgManagers struct {
|
||||||
Pip []string `mapstructure:"pip" yaml:"pip"`
|
Pip []string `mapstructure:"pip" yaml:"pip"`
|
||||||
Npm []string `mapstructure:"npm" yaml:"npm"`
|
Npm []string `mapstructure:"npm" yaml:"npm"`
|
||||||
Go []string `mapstructure:"go" yaml:"go"`
|
Go []string `mapstructure:"go" yaml:"go"`
|
||||||
|
Nala []string `mapstructure:"nala" yaml:"nala"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,18 @@ import (
|
||||||
// InstallPackages install all packages from the configuration file by installation order
|
// InstallPackages install all packages from the configuration file by installation order
|
||||||
func InstallPackages(c configuration.PkgManagers) error {
|
func InstallPackages(c configuration.PkgManagers) error {
|
||||||
color.Blue("\n# Installing packages")
|
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 {
|
for _, pkgManager := range c.InstallationOrder {
|
||||||
color.Blue("## Installing %s packages", pkgManager)
|
color.Blue("## Installing %s packages", pkgManager)
|
||||||
|
if _, ok := pkgManagers[pkgManager]; ok {
|
||||||
|
color.Blue("Skipping %s packages", pkgManager)
|
||||||
|
fmt.Println()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var pkgs []string
|
var pkgs []string
|
||||||
switch pkgManager {
|
switch pkgManager {
|
||||||
|
@ -35,6 +44,8 @@ func InstallPackages(c configuration.PkgManagers) error {
|
||||||
pkgs = c.Pip
|
pkgs = c.Pip
|
||||||
case "go":
|
case "go":
|
||||||
pkgs = c.Go
|
pkgs = c.Go
|
||||||
|
case "nala":
|
||||||
|
pkgs = c.Nala
|
||||||
default:
|
default:
|
||||||
PrintError("package manager not supported: %s\n", pkgManager)
|
PrintError("package manager not supported: %s\n", pkgManager)
|
||||||
continue
|
continue
|
||||||
|
@ -64,7 +75,14 @@ func InstallPackages(c configuration.PkgManagers) error {
|
||||||
continue
|
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 {
|
for _, pkg := range pkgs {
|
||||||
if strings.Contains(pkg, " ") {
|
if strings.Contains(pkg, " ") {
|
||||||
cmd.Args = append(cmd.Args, strings.Split(pkg, " ")...)
|
cmd.Args = append(cmd.Args, strings.Split(pkg, " ")...)
|
||||||
|
|
Reference in New Issue