Commit b279d4b3 authored by Cristian Maglie's avatar Cristian Maglie

Fixed 'feedback' package initialization order

parent 9585728e
...@@ -203,19 +203,22 @@ func toLogLevel(s string) (t logrus.Level, found bool) { ...@@ -203,19 +203,22 @@ func toLogLevel(s string) (t logrus.Level, found bool) {
} }
func preRun(verbose bool, outputFormat string, logLevel, logFile, logFormat string, noColor bool, settings *rpc.Configuration) { func preRun(verbose bool, outputFormat string, logLevel, logFile, logFormat string, noColor bool, settings *rpc.Configuration) {
// initialize inventory //
err := inventory.Init(settings.GetDirectories().GetData()) // Prepare the Feedback system
if err != nil { //
feedback.Fatal(fmt.Sprintf("Error: %v", err), feedback.ErrInitializingInventory)
}
// https://no-color.org/
color.NoColor = noColor || os.Getenv("NO_COLOR") != ""
// Set default feedback output to colorable // Set default feedback output to colorable
color.NoColor = noColor || os.Getenv("NO_COLOR") != "" // https://no-color.org/
feedback.SetOut(colorable.NewColorableStdout()) feedback.SetOut(colorable.NewColorableStdout())
feedback.SetErr(colorable.NewColorableStderr()) feedback.SetErr(colorable.NewColorableStderr())
// use the output format to configure the Feedback
format, ok := feedback.ParseOutputFormat(outputFormat)
if !ok {
feedback.Fatal(tr("Invalid output format: %s", outputFormat), feedback.ErrBadArgument)
}
feedback.SetFormat(format)
// //
// Prepare logging // Prepare logging
// //
...@@ -260,20 +263,14 @@ func preRun(verbose bool, outputFormat string, logLevel, logFile, logFormat stri ...@@ -260,20 +263,14 @@ func preRun(verbose bool, outputFormat string, logLevel, logFile, logFormat stri
logrus.SetLevel(logrusLevel) logrus.SetLevel(logrusLevel)
} }
// // Print some status info and check command is consistent
// Prepare the Feedback system logrus.Info(versioninfo.VersionInfo.Application + " version " + versioninfo.VersionInfo.VersionString)
//
// use the output format to configure the Feedback
format, ok := feedback.ParseOutputFormat(outputFormat)
if !ok {
feedback.Fatal(tr("Invalid output format: %s", outputFormat), feedback.ErrBadArgument)
}
feedback.SetFormat(format)
// //
// Print some status info and check command is consistent // Initialize inventory
// //
err := inventory.Init(settings.GetDirectories().GetData())
logrus.Info(versioninfo.VersionInfo.Application + " version " + versioninfo.VersionInfo.VersionString) if err != nil {
feedback.Fatal(fmt.Sprintf("Error: %v", err), feedback.ErrInitializingInventory)
}
} }
...@@ -651,7 +651,7 @@ func TestCLIStartupWithCorruptedInventory(t *testing.T) { ...@@ -651,7 +651,7 @@ func TestCLIStartupWithCorruptedInventory(t *testing.T) {
require.NoError(t, f.Close()) require.NoError(t, f.Close())
// the CLI should not be able to load inventory and report it to the logs // the CLI should not be able to load inventory and report it to the logs
_, stderr, err := cli.Run("core", "update-index", "-v") stdout, _, err := cli.Run("core", "update-index", "-v")
require.NoError(t, err) require.NoError(t, err)
require.Contains(t, string(stderr), "Error loading inventory store") require.Contains(t, string(stdout), "Error loading inventory store")
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment