@@ -30,6 +30,7 @@ import (
30
30
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
31
31
"github.com/arduino/go-paths-helper"
32
32
"github.com/sirupsen/logrus"
33
+ "github.com/spf13/cobra"
33
34
)
34
35
35
36
func main () {
@@ -45,6 +46,7 @@ func main() {
45
46
46
47
// Read the settings from the configuration file
47
48
openReq := & rpc.ConfigurationOpenRequest {SettingsFormat : "yaml" }
49
+ var configFileLoadingWarnings []string
48
50
if configData , err := paths .New (configFile ).ReadFile (); err == nil {
49
51
openReq .EncodedSettings = string (configData )
50
52
} else if ! os .IsNotExist (err ) {
@@ -53,9 +55,8 @@ func main() {
53
55
if resp , err := srv .ConfigurationOpen (ctx , openReq ); err != nil {
54
56
feedback .FatalError (fmt .Errorf ("couldn't load configuration: %w" , err ), feedback .ErrGeneric )
55
57
} 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
59
60
}
60
61
61
62
// Get the current settings from the server
@@ -70,6 +71,15 @@ func main() {
70
71
71
72
// Setup command line parser with the server and settings
72
73
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
+ }
73
83
74
84
// Execute the command line
75
85
if err := arduinoCmd .ExecuteContext (ctx ); err != nil {
0 commit comments