@@ -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
3536func 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