mirror of
https://github.com/mudler/luet.git
synced 2025-08-13 21:15:55 +00:00
Do not register viper bindings in init
Otherwise they get overlapped. Use PreRun instead
This commit is contained in:
parent
914ac68eea
commit
b751b02830
27
cmd/build.go
27
cmd/build.go
@ -34,10 +34,20 @@ var buildCmd = &cobra.Command{
|
|||||||
Use: "build <package name> <package name> <package name> ...",
|
Use: "build <package name> <package name> <package name> ...",
|
||||||
Short: "build a package or a tree",
|
Short: "build a package or a tree",
|
||||||
Long: `build packages or trees from luet tree definitions. Packages are in [category]/[name]-[version] form`,
|
Long: `build packages or trees from luet tree definitions. Packages are in [category]/[name]-[version] form`,
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
viper.BindPFlag("tree", cmd.Flags().Lookup("tree"))
|
||||||
|
viper.BindPFlag("destination", cmd.Flags().Lookup("destination"))
|
||||||
|
viper.BindPFlag("backend", cmd.Flags().Lookup("backend"))
|
||||||
|
viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency"))
|
||||||
|
viper.BindPFlag("privileged", cmd.Flags().Lookup("privileged"))
|
||||||
|
viper.BindPFlag("database", cmd.Flags().Lookup("database"))
|
||||||
|
viper.BindPFlag("revdeps", cmd.Flags().Lookup("revdeps"))
|
||||||
|
viper.BindPFlag("all", cmd.Flags().Lookup("all"))
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
src := viper.GetString("tree")
|
src := viper.GetString("tree")
|
||||||
dst := viper.GetString("output")
|
dst := viper.GetString("destination")
|
||||||
concurrency := viper.GetInt("concurrency")
|
concurrency := viper.GetInt("concurrency")
|
||||||
backendType := viper.GetString("backend")
|
backendType := viper.GetString("backend")
|
||||||
privileged := viper.GetBool("privileged")
|
privileged := viper.GetBool("privileged")
|
||||||
@ -70,6 +80,8 @@ var buildCmd = &cobra.Command{
|
|||||||
generalRecipe := tree.NewCompilerRecipe(db)
|
generalRecipe := tree.NewCompilerRecipe(db)
|
||||||
|
|
||||||
Info("Loading", src)
|
Info("Loading", src)
|
||||||
|
Info("Building in", dst)
|
||||||
|
|
||||||
err := generalRecipe.Load(src)
|
err := generalRecipe.Load(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal("Error: " + err.Error())
|
Fatal("Error: " + err.Error())
|
||||||
@ -110,6 +122,7 @@ var buildCmd = &cobra.Command{
|
|||||||
Fatal("Error: " + err.Error())
|
Fatal("Error: " + err.Error())
|
||||||
}
|
}
|
||||||
Info(":package: Selecting ", p.GetName(), p.GetVersion())
|
Info(":package: Selecting ", p.GetName(), p.GetVersion())
|
||||||
|
spec.SetOutputPath(dst)
|
||||||
compilerSpecs.Add(spec)
|
compilerSpecs.Add(spec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -141,21 +154,13 @@ func init() {
|
|||||||
Fatal(err)
|
Fatal(err)
|
||||||
}
|
}
|
||||||
buildCmd.Flags().String("tree", path, "Source luet tree")
|
buildCmd.Flags().String("tree", path, "Source luet tree")
|
||||||
viper.BindPFlag("tree", buildCmd.Flags().Lookup("tree"))
|
|
||||||
buildCmd.Flags().String("output", path, "Destination folder")
|
|
||||||
viper.BindPFlag("output", buildCmd.Flags().Lookup("output"))
|
|
||||||
buildCmd.Flags().String("backend", "docker", "backend used (docker,img)")
|
buildCmd.Flags().String("backend", "docker", "backend used (docker,img)")
|
||||||
viper.BindPFlag("backend", buildCmd.Flags().Lookup("backend"))
|
|
||||||
buildCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency")
|
buildCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency")
|
||||||
viper.BindPFlag("concurrency", buildCmd.Flags().Lookup("concurrency"))
|
|
||||||
buildCmd.Flags().Bool("privileged", false, "Privileged (Keep permissions)")
|
buildCmd.Flags().Bool("privileged", false, "Privileged (Keep permissions)")
|
||||||
viper.BindPFlag("privileged", buildCmd.Flags().Lookup("privileged"))
|
|
||||||
buildCmd.Flags().String("database", "memory", "database used for solving (memory,boltdb)")
|
buildCmd.Flags().String("database", "memory", "database used for solving (memory,boltdb)")
|
||||||
viper.BindPFlag("database", buildCmd.Flags().Lookup("database"))
|
|
||||||
buildCmd.Flags().Bool("revdeps", false, "Build with revdeps")
|
buildCmd.Flags().Bool("revdeps", false, "Build with revdeps")
|
||||||
viper.BindPFlag("revdeps", buildCmd.Flags().Lookup("revdeps"))
|
|
||||||
|
|
||||||
buildCmd.Flags().Bool("all", false, "Build all packages in the tree")
|
buildCmd.Flags().Bool("all", false, "Build all packages in the tree")
|
||||||
viper.BindPFlag("all", buildCmd.Flags().Lookup("all"))
|
buildCmd.Flags().String("destination", path, "Destination folder")
|
||||||
|
|
||||||
RootCmd.AddCommand(buildCmd)
|
RootCmd.AddCommand(buildCmd)
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,11 @@ var convertCmd = &cobra.Command{
|
|||||||
Use: "convert",
|
Use: "convert",
|
||||||
Short: "convert other package manager tree into luet",
|
Short: "convert other package manager tree into luet",
|
||||||
Long: `Parses external PM and produces a luet parsable tree`,
|
Long: `Parses external PM and produces a luet parsable tree`,
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
viper.BindPFlag("type", cmd.Flags().Lookup("type"))
|
||||||
|
viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency"))
|
||||||
|
viper.BindPFlag("database", cmd.Flags().Lookup("database"))
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
t := viper.GetString("type")
|
t := viper.GetString("type")
|
||||||
@ -87,11 +92,8 @@ var convertCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
convertCmd.Flags().String("type", "gentoo", "source type")
|
convertCmd.Flags().String("type", "gentoo", "source type")
|
||||||
viper.BindPFlag("type", convertCmd.Flags().Lookup("type"))
|
|
||||||
convertCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency")
|
convertCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency")
|
||||||
viper.BindPFlag("concurrency", convertCmd.Flags().Lookup("concurrency"))
|
|
||||||
convertCmd.Flags().String("database", "memory", "database used for solving (memory,boltdb)")
|
convertCmd.Flags().String("database", "memory", "database used for solving (memory,boltdb)")
|
||||||
viper.BindPFlag("database", convertCmd.Flags().Lookup("database"))
|
|
||||||
|
|
||||||
RootCmd.AddCommand(convertCmd)
|
RootCmd.AddCommand(convertCmd)
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,14 @@ var createrepoCmd = &cobra.Command{
|
|||||||
Use: "create-repo",
|
Use: "create-repo",
|
||||||
Short: "Create a luet repository from a build",
|
Short: "Create a luet repository from a build",
|
||||||
Long: `Generate and renew repository metadata`,
|
Long: `Generate and renew repository metadata`,
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
viper.BindPFlag("packages", cmd.Flags().Lookup("packages"))
|
||||||
|
viper.BindPFlag("tree", cmd.Flags().Lookup("tree"))
|
||||||
|
viper.BindPFlag("output", cmd.Flags().Lookup("output"))
|
||||||
|
viper.BindPFlag("name", cmd.Flags().Lookup("name"))
|
||||||
|
viper.BindPFlag("uri", cmd.Flags().Lookup("uri"))
|
||||||
|
viper.BindPFlag("type", cmd.Flags().Lookup("type"))
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
tree := viper.GetString("tree")
|
tree := viper.GetString("tree")
|
||||||
@ -56,20 +64,11 @@ func init() {
|
|||||||
Fatal(err)
|
Fatal(err)
|
||||||
}
|
}
|
||||||
createrepoCmd.Flags().String("packages", path, "Packages folder (output from build)")
|
createrepoCmd.Flags().String("packages", path, "Packages folder (output from build)")
|
||||||
viper.BindPFlag("packages", createrepoCmd.Flags().Lookup("packages"))
|
|
||||||
|
|
||||||
createrepoCmd.Flags().String("tree", path, "Source luet tree")
|
createrepoCmd.Flags().String("tree", path, "Source luet tree")
|
||||||
viper.BindPFlag("tree", createrepoCmd.Flags().Lookup("tree"))
|
|
||||||
createrepoCmd.Flags().String("output", path, "Destination folder")
|
createrepoCmd.Flags().String("output", path, "Destination folder")
|
||||||
viper.BindPFlag("output", createrepoCmd.Flags().Lookup("output"))
|
|
||||||
createrepoCmd.Flags().String("name", "luet", "Repository name")
|
createrepoCmd.Flags().String("name", "luet", "Repository name")
|
||||||
viper.BindPFlag("name", createrepoCmd.Flags().Lookup("name"))
|
|
||||||
|
|
||||||
createrepoCmd.Flags().String("uri", path, "Repository uri")
|
createrepoCmd.Flags().String("uri", path, "Repository uri")
|
||||||
viper.BindPFlag("uri", createrepoCmd.Flags().Lookup("uri"))
|
|
||||||
|
|
||||||
createrepoCmd.Flags().String("type", "local", "Repository type (local)")
|
createrepoCmd.Flags().String("type", "local", "Repository type (local)")
|
||||||
viper.BindPFlag("type", createrepoCmd.Flags().Lookup("type"))
|
|
||||||
|
|
||||||
RootCmd.AddCommand(createrepoCmd)
|
RootCmd.AddCommand(createrepoCmd)
|
||||||
}
|
}
|
||||||
|
@ -32,13 +32,19 @@ import (
|
|||||||
var installCmd = &cobra.Command{
|
var installCmd = &cobra.Command{
|
||||||
Use: "install <pkg1> <pkg2> ...",
|
Use: "install <pkg1> <pkg2> ...",
|
||||||
Short: "Install a package",
|
Short: "Install a package",
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
viper.BindPFlag("system-dbpath", cmd.Flags().Lookup("system-dbpath"))
|
||||||
|
viper.BindPFlag("system-target", cmd.Flags().Lookup("system-target"))
|
||||||
|
viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency"))
|
||||||
|
},
|
||||||
Long: `Install packages in parallel`,
|
Long: `Install packages in parallel`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
c := installer.Repositories{}
|
c := []*installer.LuetRepository{}
|
||||||
err := viper.UnmarshalKey("system-repositories", &c)
|
err := viper.UnmarshalKey("system-repositories", &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal("Error: " + err.Error())
|
Fatal("Error: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var toInstall []pkg.Package
|
var toInstall []pkg.Package
|
||||||
|
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
@ -55,11 +61,22 @@ var installCmd = &cobra.Command{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This shouldn't be necessary, but we need to unmarshal the repositories to a concrete struct, thus we need to port them back to the Repositories type
|
||||||
|
synced := installer.Repositories{}
|
||||||
|
for _, toSync := range c {
|
||||||
|
s, err := toSync.Sync()
|
||||||
|
if err != nil {
|
||||||
|
Fatal("Error: " + err.Error())
|
||||||
|
}
|
||||||
|
synced = append(synced, s)
|
||||||
|
}
|
||||||
|
|
||||||
inst := installer.NewLuetInstaller(viper.GetInt("concurrency"))
|
inst := installer.NewLuetInstaller(viper.GetInt("concurrency"))
|
||||||
|
|
||||||
inst.Repositories(c)
|
inst.Repositories(synced)
|
||||||
|
|
||||||
systemDB := pkg.NewBoltDatabase(filepath.Join(viper.GetString("system-dbpath"), "luet"))
|
os.MkdirAll(viper.GetString("system-dbpath"), os.ModePerm)
|
||||||
|
systemDB := pkg.NewBoltDatabase(filepath.Join(viper.GetString("system-dbpath"), "luet.db"))
|
||||||
system := &installer.System{Database: systemDB, Target: viper.GetString("system-target")}
|
system := &installer.System{Database: systemDB, Target: viper.GetString("system-target")}
|
||||||
err = inst.Install(toInstall, system)
|
err = inst.Install(toInstall, system)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -74,13 +91,8 @@ func init() {
|
|||||||
Fatal(err)
|
Fatal(err)
|
||||||
}
|
}
|
||||||
installCmd.Flags().String("system-dbpath", path, "System db path")
|
installCmd.Flags().String("system-dbpath", path, "System db path")
|
||||||
viper.BindPFlag("system-dbpath", installCmd.Flags().Lookup("system-dbpath"))
|
|
||||||
|
|
||||||
installCmd.Flags().String("system-target", path, "System rootpath")
|
installCmd.Flags().String("system-target", path, "System rootpath")
|
||||||
viper.BindPFlag("system-target", installCmd.Flags().Lookup("system-target"))
|
|
||||||
|
|
||||||
installCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency")
|
installCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency")
|
||||||
viper.BindPFlag("concurrency", installCmd.Flags().Lookup("concurrency"))
|
|
||||||
|
|
||||||
RootCmd.AddCommand(installCmd)
|
RootCmd.AddCommand(installCmd)
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,10 @@ var queryCmd = &cobra.Command{
|
|||||||
Use: "query install <pkg>",
|
Use: "query install <pkg>",
|
||||||
Short: "query other package manager tree into luet",
|
Short: "query other package manager tree into luet",
|
||||||
Long: `Parses external PM and produces a luet parsable tree`,
|
Long: `Parses external PM and produces a luet parsable tree`,
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
viper.BindPFlag("input", cmd.Flags().Lookup("input"))
|
||||||
|
viper.BindPFlag("database", cmd.Flags().Lookup("database"))
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
input := viper.GetString("input")
|
input := viper.GetString("input")
|
||||||
@ -104,9 +108,7 @@ var queryCmd = &cobra.Command{
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
queryCmd.Flags().String("input", "", "source folder")
|
queryCmd.Flags().String("input", "", "source folder")
|
||||||
viper.BindPFlag("input", queryCmd.Flags().Lookup("input"))
|
|
||||||
queryCmd.Flags().String("database", "memory", "database used for solving (memory,boltdb)")
|
queryCmd.Flags().String("database", "memory", "database used for solving (memory,boltdb)")
|
||||||
viper.BindPFlag("database", queryCmd.Flags().Lookup("database"))
|
|
||||||
|
|
||||||
RootCmd.AddCommand(queryCmd)
|
RootCmd.AddCommand(queryCmd)
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,11 @@ var uninstallCmd = &cobra.Command{
|
|||||||
Use: "uninstall <pkg>",
|
Use: "uninstall <pkg>",
|
||||||
Short: "Uninstall a package",
|
Short: "Uninstall a package",
|
||||||
Long: `Uninstall packages`,
|
Long: `Uninstall packages`,
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
viper.BindPFlag("system-dbpath", cmd.Flags().Lookup("system-dbpath"))
|
||||||
|
viper.BindPFlag("system-target", cmd.Flags().Lookup("system-target"))
|
||||||
|
viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency"))
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
Fatal("Wrong number of args")
|
Fatal("Wrong number of args")
|
||||||
@ -50,8 +55,8 @@ var uninstallCmd = &cobra.Command{
|
|||||||
version := packageInfo[0][7]
|
version := packageInfo[0][7]
|
||||||
|
|
||||||
inst := installer.NewLuetInstaller(viper.GetInt("concurrency"))
|
inst := installer.NewLuetInstaller(viper.GetInt("concurrency"))
|
||||||
|
os.MkdirAll(viper.GetString("system-dbpath"), os.ModePerm)
|
||||||
systemDB := pkg.NewBoltDatabase(filepath.Join(viper.GetString("system-dbpath"), "luet"))
|
systemDB := pkg.NewBoltDatabase(filepath.Join(viper.GetString("system-dbpath"), "luet.db"))
|
||||||
system := &installer.System{Database: systemDB, Target: viper.GetString("system-target")}
|
system := &installer.System{Database: systemDB, Target: viper.GetString("system-target")}
|
||||||
err = inst.Uninstall(&pkg.DefaultPackage{Name: name, Category: category, Version: version}, system)
|
err = inst.Uninstall(&pkg.DefaultPackage{Name: name, Category: category, Version: version}, system)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -66,13 +71,7 @@ func init() {
|
|||||||
Fatal(err)
|
Fatal(err)
|
||||||
}
|
}
|
||||||
uninstallCmd.Flags().String("system-dbpath", path, "System db path")
|
uninstallCmd.Flags().String("system-dbpath", path, "System db path")
|
||||||
viper.BindPFlag("system-dbpath", uninstallCmd.Flags().Lookup("system-dbpath"))
|
|
||||||
|
|
||||||
uninstallCmd.Flags().String("system-target", path, "System rootpath")
|
uninstallCmd.Flags().String("system-target", path, "System rootpath")
|
||||||
viper.BindPFlag("system-target", uninstallCmd.Flags().Lookup("system-target"))
|
|
||||||
|
|
||||||
uninstallCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency")
|
uninstallCmd.Flags().Int("concurrency", runtime.NumCPU(), "Concurrency")
|
||||||
viper.BindPFlag("concurrency", uninstallCmd.Flags().Lookup("concurrency"))
|
|
||||||
|
|
||||||
RootCmd.AddCommand(uninstallCmd)
|
RootCmd.AddCommand(uninstallCmd)
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ func (l *LuetInstaller) Install(p []pkg.Package, s *System) error {
|
|||||||
// Get installed definition
|
// Get installed definition
|
||||||
installed, err := s.World()
|
installed, err := s.World()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed generating installed world ")
|
return errors.Wrap(err, "Failed generating installed world")
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute a "big" world
|
// compute a "big" world
|
||||||
|
Loading…
Reference in New Issue
Block a user