Skip to content

Commit 0451b93

Browse files
committed
Show config-load warning after feedback package initialization
1 parent 3304be6 commit 0451b93

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

main.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3131
"github.com/arduino/go-paths-helper"
3232
"github.com/sirupsen/logrus"
33+
"github.com/spf13/cobra"
3334
)
3435

3536
func main() {
@@ -45,6 +46,7 @@ func main() {
4546

4647
// Read the settings from the configuration file
4748
openReq := &rpc.ConfigurationOpenRequest{SettingsFormat: "yaml"}
49+
var configFileLoadingWarnings []string
4850
if configData, err := paths.New(configFile).ReadFile(); err == nil {
4951
openReq.EncodedSettings = string(configData)
5052
} else if !os.IsNotExist(err) {
@@ -53,9 +55,8 @@ func main() {
5355
if resp, err := srv.ConfigurationOpen(ctx, openReq); err != nil {
5456
feedback.FatalError(fmt.Errorf("couldn't load configuration: %w", err), feedback.ErrGeneric)
5557
} else if warnings := resp.GetWarnings(); len(warnings) > 0 {
56-
for _, warning := range warnings {
57-
feedback.Warning(warning)
58-
}
58+
// Save the warnings to show them later when the feedback package is fully initialized
59+
configFileLoadingWarnings = warnings
5960
}
6061

6162
// Get the current settings from the server
@@ -70,6 +71,15 @@ func main() {
7071

7172
// Setup command line parser with the server and settings
7273
arduinoCmd := cli.NewCommand(srv)
74+
parentPreRun := arduinoCmd.PersistentPreRun
75+
arduinoCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
76+
if parentPreRun != nil {
77+
parentPreRun(cmd, args)
78+
}
79+
for _, warning := range configFileLoadingWarnings {
80+
feedback.Warning(warning)
81+
}
82+
}
7383

7484
// Execute the command line
7585
if err := arduinoCmd.ExecuteContext(ctx); err != nil {

0 commit comments

Comments
 (0)