diff --git a/cmd/convert.go b/cmd/convert.go index 6819a767..a3bc5c57 100644 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -15,10 +15,9 @@ package cmd import ( - "fmt" - "log" "os" + . "github.com/mudler/luet/pkg/logger" tree "github.com/mudler/luet/pkg/tree" "github.com/mudler/luet/pkg/tree/builder/gentoo" @@ -36,12 +35,13 @@ var convertCmd = &cobra.Command{ c := viper.GetInt("concurrency") if len(args) != 2 { - log.Fatalln("Incorrect number of arguments") + Error("Incorrect number of arguments") + os.Exit(1) } input := args[0] output := args[1] - fmt.Println("Converting trees from" + input + " [" + t + "]") + Info("Converting trees from" + input + " [" + t + "]") var builder tree.Parser switch t { @@ -53,20 +53,20 @@ var convertCmd = &cobra.Command{ packageTree, err := builder.Generate(input) if err != nil { - fmt.Println("Error: " + err.Error()) + Error("Error: " + err.Error()) os.Exit(1) } defer packageTree.GetPackageSet().Clean() - fmt.Println("Tree generated") + Info("Tree generated") generalRecipe := tree.NewGeneralRecipe() - fmt.Println("Saving generated tree to " + output) + Info("Saving generated tree to " + output) generalRecipe.WithTree(packageTree) err = generalRecipe.Save(output) if err != nil { - fmt.Println("Error: " + err.Error()) + Error("Error: " + err.Error()) os.Exit(1) } }, diff --git a/cmd/root.go b/cmd/root.go index b4224082..cfeca77e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -16,12 +16,12 @@ package cmd import ( - "fmt" - "log" "os" "path" "path/filepath" + . "github.com/mudler/luet/pkg/logger" + "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -40,7 +40,7 @@ var RootCmd = &cobra.Command{ // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { if err := RootCmd.Execute(); err != nil { - fmt.Println(err) + Error(err) os.Exit(-1) } } @@ -55,12 +55,13 @@ func init() { func initConfig() { dir, err := filepath.Abs(filepath.Dir(os.Args[0])) if err != nil { - log.Fatal(err) + Error(err) + os.Exit(1) } viper.SetConfigName(".luet") // name of config file (without extension) if cfgFile != "" { // enable ability to specify config file via flag - fmt.Println(">>> cfgFile: ", cfgFile) + Info(">>> cfgFile: ", cfgFile) viper.SetConfigFile(cfgFile) configDir := path.Dir(cfgFile) if configDir != "." && configDir != dir { @@ -75,9 +76,9 @@ func initConfig() { // If a config file is found, read it in. if err := viper.ReadInConfig(); err == nil { - fmt.Println("Using config file:", viper.ConfigFileUsed()) + Info("Using config file:", viper.ConfigFileUsed()) } else { - fmt.Println(err) + Error(err) } } diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 5849e475..3aa5c13b 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -12,7 +12,6 @@ import ( var s *spinner.Spinner func Spinner(i int) { - if i > 43 { i = 43 } @@ -34,46 +33,46 @@ func SpinnerStop() { func Warning(msg ...interface{}) { if s != nil { SpinnerText(Sprintf(msg), Bold(Yellow("Warn")).BgBlack().String()) - return + // return } cmd := []interface{}{Bold(Yellow("Warn")).BgBlack().String()} for _, f := range msg { cmd = append(cmd, f) } - fmt.Println(cmd) + fmt.Println(cmd...) } func Debug(msg ...interface{}) { if s != nil { SpinnerText(Sprintf(msg), Bold(White("Debug")).BgBlack().String()) - return + // return } cmd := []interface{}{Bold(White("Debug")).String()} for _, f := range msg { cmd = append(cmd, f) } - fmt.Println(cmd) + fmt.Println(cmd...) } func Info(msg ...interface{}) { if s != nil { SpinnerText(Sprintf(msg), Bold(Blue("Info")).BgBlack().String()) - return + // return } cmd := []interface{}{Bold(Green("Info")).String()} for _, f := range msg { cmd = append(cmd, f) } - fmt.Println(cmd) + fmt.Println(cmd...) } func Error(msg ...interface{}) { if s != nil { SpinnerText(Sprintf(msg), Bold(Red("Error")).BgBlack().String()) - return + // return } cmd := []interface{}{Bold(Red("Error")).String()} for _, f := range msg { cmd = append(cmd, f) } - fmt.Println(cmd) + fmt.Println(cmd...) } diff --git a/pkg/tree/builder/gentoo/gentoo.go b/pkg/tree/builder/gentoo/gentoo.go index 2385c2de..f206946a 100644 --- a/pkg/tree/builder/gentoo/gentoo.go +++ b/pkg/tree/builder/gentoo/gentoo.go @@ -66,7 +66,6 @@ func (gb *GentooBuilder) scanEbuild(path string, t pkg.Tree) error { return err } } - } return nil } @@ -75,7 +74,7 @@ func (gb *GentooBuilder) worker(i int, wg *sync.WaitGroup, s chan string, t pkg. defer wg.Done() for path := range s { - SpinnerText(" "+path, "Scanning ") + Info("Scanning", path) err := gb.scanEbuild(path, t) if err != nil { Error("scanning ebuild: " + path) @@ -121,7 +120,9 @@ func (gb *GentooBuilder) Generate(dir string) (pkg.Tree, error) { } close(toScan) + Debug("Waiting for goroutines to finish") wg.Wait() + Info("Scan finished") Info("Resolving deps") return tree, tree.ResolveDeps(gb.Concurrency) } diff --git a/pkg/tree/builder/gentoo/simpleparser.go b/pkg/tree/builder/gentoo/simpleparser.go index c010579d..b531f7b1 100644 --- a/pkg/tree/builder/gentoo/simpleparser.go +++ b/pkg/tree/builder/gentoo/simpleparser.go @@ -27,6 +27,8 @@ import ( "regexp" "strings" + . "github.com/mudler/luet/pkg/logger" + pkg "github.com/mudler/luet/pkg/package" "mvdan.cc/sh/expand" "mvdan.cc/sh/shell" @@ -55,7 +57,7 @@ func SourceFile(ctx context.Context, path string) (map[string]expand.Variable, e func (ep *SimpleEbuildParser) ScanEbuild(path string, tree pkg.Tree) ([]pkg.Package, error) { defer func() { if r := recover(); r != nil { - fmt.Println("Recovered in scanebuild", r) + Error(r) } }() file := filepath.Base(path)