Skip to content

Rewrite the output system #345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 28, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix config dump json format
  • Loading branch information
Massimiliano Pippi committed Aug 28, 2019
commit 2775ff0e56c8b6e0c1eabcdde72e0fa7107d78da
59 changes: 57 additions & 2 deletions cli/config/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package config

import (
"fmt"
"net/url"
"os"

"github.com/arduino/arduino-cli/cli/errorcodes"
Expand All @@ -28,6 +28,27 @@ import (
"github.com/spf13/cobra"
)

// FIXME: The way the Config objects is marshalled into JSON shouldn't be here,
// this is a temporary fix for the command `arduino-cli config dump --format json`
type jsonConfig struct {
ProxyType string `json:"proxy_type"`
ProxyManualConfig *jsonProxyConfig `json:"manual_configs,omitempty"`
SketchbookPath string `json:"sketchbook_path,omitempty"`
ArduinoDataDir string `json:"arduino_data,omitempty"`
ArduinoDownloadsDir string `json:"arduino_downloads_dir,omitempty"`
BoardsManager *jsonBoardsManagerConfig `json:"board_manager"`
}

type jsonBoardsManagerConfig struct {
AdditionalURLS []*url.URL `json:"additional_urls,omitempty"`
}

type jsonProxyConfig struct {
Hostname string `json:"hostname"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"` // can be encrypted, see issue #71
}

var dumpCmd = &cobra.Command{
Use: "dump",
Short: "Prints the current configuration",
Expand All @@ -46,5 +67,39 @@ func runDumpCommand(cmd *cobra.Command, args []string) {
os.Exit(errorcodes.ErrGeneric)
}

fmt.Println(string(data))
c := globals.Config

if globals.OutputFormat == "json" {
sketchbookDir := ""
if c.SketchbookDir != nil {
sketchbookDir = c.SketchbookDir.String()
}

arduinoDataDir := ""
if c.DataDir != nil {
arduinoDataDir = c.DataDir.String()
}

arduinoDownloadsDir := ""
if c.ArduinoDownloadsDir != nil {
arduinoDownloadsDir = c.ArduinoDownloadsDir.String()
}

feedback.PrintJSON(jsonConfig{
ProxyType: c.ProxyType,
ProxyManualConfig: &jsonProxyConfig{
Hostname: c.ProxyHostname,
Username: c.ProxyUsername,
Password: c.ProxyPassword,
},
SketchbookPath: sketchbookDir,
ArduinoDataDir: arduinoDataDir,
ArduinoDownloadsDir: arduinoDownloadsDir,
BoardsManager: &jsonBoardsManagerConfig{
AdditionalURLS: c.BoardManagerAdditionalUrls,
},
})
} else {
feedback.Print(string(data))
}
}