Skip to content

Commit 2775ff0

Browse files
author
Massimiliano Pippi
committed
fix config dump json format
1 parent c3df6db commit 2775ff0

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

cli/config/dump.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package config
1919

2020
import (
21-
"fmt"
21+
"net/url"
2222
"os"
2323

2424
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -28,6 +28,27 @@ import (
2828
"github.com/spf13/cobra"
2929
)
3030

31+
// FIXME: The way the Config objects is marshalled into JSON shouldn't be here,
32+
// this is a temporary fix for the command `arduino-cli config dump --format json`
33+
type jsonConfig struct {
34+
ProxyType string `json:"proxy_type"`
35+
ProxyManualConfig *jsonProxyConfig `json:"manual_configs,omitempty"`
36+
SketchbookPath string `json:"sketchbook_path,omitempty"`
37+
ArduinoDataDir string `json:"arduino_data,omitempty"`
38+
ArduinoDownloadsDir string `json:"arduino_downloads_dir,omitempty"`
39+
BoardsManager *jsonBoardsManagerConfig `json:"board_manager"`
40+
}
41+
42+
type jsonBoardsManagerConfig struct {
43+
AdditionalURLS []*url.URL `json:"additional_urls,omitempty"`
44+
}
45+
46+
type jsonProxyConfig struct {
47+
Hostname string `json:"hostname"`
48+
Username string `json:"username,omitempty"`
49+
Password string `json:"password,omitempty"` // can be encrypted, see issue #71
50+
}
51+
3152
var dumpCmd = &cobra.Command{
3253
Use: "dump",
3354
Short: "Prints the current configuration",
@@ -46,5 +67,39 @@ func runDumpCommand(cmd *cobra.Command, args []string) {
4667
os.Exit(errorcodes.ErrGeneric)
4768
}
4869

49-
fmt.Println(string(data))
70+
c := globals.Config
71+
72+
if globals.OutputFormat == "json" {
73+
sketchbookDir := ""
74+
if c.SketchbookDir != nil {
75+
sketchbookDir = c.SketchbookDir.String()
76+
}
77+
78+
arduinoDataDir := ""
79+
if c.DataDir != nil {
80+
arduinoDataDir = c.DataDir.String()
81+
}
82+
83+
arduinoDownloadsDir := ""
84+
if c.ArduinoDownloadsDir != nil {
85+
arduinoDownloadsDir = c.ArduinoDownloadsDir.String()
86+
}
87+
88+
feedback.PrintJSON(jsonConfig{
89+
ProxyType: c.ProxyType,
90+
ProxyManualConfig: &jsonProxyConfig{
91+
Hostname: c.ProxyHostname,
92+
Username: c.ProxyUsername,
93+
Password: c.ProxyPassword,
94+
},
95+
SketchbookPath: sketchbookDir,
96+
ArduinoDataDir: arduinoDataDir,
97+
ArduinoDownloadsDir: arduinoDownloadsDir,
98+
BoardsManager: &jsonBoardsManagerConfig{
99+
AdditionalURLS: c.BoardManagerAdditionalUrls,
100+
},
101+
})
102+
} else {
103+
feedback.Print(string(data))
104+
}
50105
}

0 commit comments

Comments
 (0)