18
18
package config
19
19
20
20
import (
21
- "fmt "
21
+ "net/url "
22
22
"os"
23
23
24
24
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -28,6 +28,27 @@ import (
28
28
"github.com/spf13/cobra"
29
29
)
30
30
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
+
31
52
var dumpCmd = & cobra.Command {
32
53
Use : "dump" ,
33
54
Short : "Prints the current configuration" ,
@@ -46,5 +67,39 @@ func runDumpCommand(cmd *cobra.Command, args []string) {
46
67
os .Exit (errorcodes .ErrGeneric )
47
68
}
48
69
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
+ }
50
105
}
0 commit comments