// Copyright © 2019 Ettore Di Giacinto // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, see . package cmd import ( "fmt" "log" "os" pkg "github.com/mudler/luet/pkg/package" "github.com/mudler/luet/pkg/solver" tree "github.com/mudler/luet/pkg/tree" "github.com/spf13/cobra" "github.com/spf13/viper" ) var queryCmd = &cobra.Command{ Use: "query install ", Short: "query other package manager tree into luet", Long: `Parses external PM and produces a luet parsable tree`, Run: func(cmd *cobra.Command, args []string) { input := viper.GetString("input") if len(args) != 3 { log.Fatalln("Incorrect number of arguments") } generalRecipe := tree.NewGeneralRecipe() fmt.Println("Loading generated tree from " + input) err := generalRecipe.Load(input) if err != nil { fmt.Println("Error: " + err.Error()) os.Exit(1) } defer generalRecipe.Tree().GetPackageSet().Clean() t := args[0] v := args[1] version := args[2] switch t { case "install": // XXX: pack needs to be the same which is present in world. // Tree caches generated world when using FindPackage pack, err := generalRecipe.Tree().FindPackage(&pkg.DefaultPackage{Name: v, Version: version}) if err != nil { fmt.Println("Error: " + err.Error()) os.Exit(1) } fmt.Println("Install query from " + input + " [" + v + "]") world, err := generalRecipe.Tree().World() if err != nil { fmt.Println("Error: " + err.Error()) os.Exit(1) } fmt.Println(">>> World") for _, packss := range world { fmt.Println(packss) } s := solver.NewSolver([]pkg.Package{}, world) solution, err := s.Install([]pkg.Package{pack}) if err != nil { fmt.Println("Error: " + err.Error()) os.Exit(1) } fmt.Println(">>> Solution") for _, assertion := range solution { fmt.Println(assertion.Package, assertion.Value) for _, req := range assertion.Package.GetRequires() { fmt.Println("\t-> ", req) } for _, con := range assertion.Package.GetConflicts() { fmt.Println("\t!! ", con) } } } }, } func init() { queryCmd.Flags().String("input", "", "source folder") viper.BindPFlag("input", queryCmd.Flags().Lookup("input")) RootCmd.AddCommand(queryCmd) }