Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9585728

Browse filesBrowse files
committed
Show config-load warning after feedback package initialization
1 parent a58c350 commit 9585728
Copy full SHA for 9585728

File tree

Expand file treeCollapse file tree

1 file changed

+13
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+13
-3
lines changed

‎main.go

Copy file name to clipboardExpand all lines: main.go
+13-3Lines changed: 13 additions & 3 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.