10000 add "config get" command to print settings values by ardnew · Pull Request #2307 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

add "config get" command to print settings values #2307

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 10 commits into from
Feb 14, 2024
Prev Previous commit
Next Next commit
config/get: do not wrap JSON output in YAML
  • Loading branch information
ardnew committed Feb 8, 2024
commit 926d850ea02ab304ffaaa92a24bf101cc9f62656
15 changes: 8 additions & 7 deletions internal/cli/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package config

import (
"os"
"reflect"

"github.com/arduino/arduino-cli/commands/daemon"
"github.com/arduino/arduino-cli/internal/cli/configuration"
"github.com/arduino/arduino-cli/internal/cli/feedback"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

func initGetCommand() *cobra.Command {
Expand Down Expand Up @@ -53,14 +53,15 @@ func runGetCommand(cmd *cobra.Command, args []string) {
if err != nil {
feedback.Fatal(tr("Cannot get the key %[1]s: %[2]v", toGet, err), feedback.ErrGeneric)
}
feedback.PrintResult(resp.GetJsonData())
feedback.PrintResult(getResult{key: toGet, data: resp.GetJsonData()})
}
}

// output from this command may require special formatting.
// create a dedicated feedback.Result implementation to safely handle
// any changes to the configuration.Settings struct.
type getResult struct {
key string
data interface{}
}

Expand All @@ -69,10 +70,10 @@ func (gr getResult) Data() interface{} {
}

func (gr getResult) String() string {
gs, err := yaml.Marshal(gr.data)
if err != nil {
gs, ok := gr.data.(string)
if !ok {
// Should never happen
panic(tr("unable to marshal config to YAML: %v", err))
panic(tr("Cannot get key %s value as string: %v", gr.key, gr.data))
}
return string(gs)
return gs
}
0