Commit 3c5aeec1 authored by Cristian Maglie's avatar Cristian Maglie

'board details' shows info on selected options

This allows to show which option is selected with defaults or with
different FQBNs.

For example:

    $ arduino-cli board details arduino:avr:nano
    Board name: Arduino Nano

    Option:     Processor                         cpu
                ATmega328P                       cpu=atmega328
                ATmega328P (Old Bootloader)       cpu=atmega328old
                ATmega168                         cpu=atmega168

or:

    $ arduino-cli board details arduino:avr:nano:cpu=atmega328old
    Board name: Arduino Nano

    Option:     Processor                         cpu
                ATmega328P                        cpu=atmega328
                ATmega328P (Old Bootloader)      cpu=atmega328old
                ATmega168                         cpu=atmega168
parent d92bfb9d
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"encoding/json" "encoding/json"
"os" "os"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/output" "github.com/arduino/arduino-cli/output"
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
...@@ -42,8 +43,13 @@ func initDetailsCommand() *cobra.Command { ...@@ -42,8 +43,13 @@ func initDetailsCommand() *cobra.Command {
func runDetailsCommand(cmd *cobra.Command, args []string) { func runDetailsCommand(cmd *cobra.Command, args []string) {
pm := commands.InitPackageManager() pm := commands.InitPackageManager()
fqbnIn := args[0] fqbn, err := cores.ParseFQBN(args[0])
board, err := pm.FindBoardWithFQBN(fqbnIn) if err != nil {
formatter.PrintError(err, "Error parsing fqbn")
os.Exit(commands.ErrBadArgument)
}
_, _, board, _, _, err := pm.ResolveFQBN(fqbn)
if err != nil { if err != nil {
formatter.PrintError(err, "Error loading board data") formatter.PrintError(err, "Error loading board data")
os.Exit(commands.ErrBadArgument) os.Exit(commands.ErrBadArgument)
...@@ -53,17 +59,22 @@ func runDetailsCommand(cmd *cobra.Command, args []string) { ...@@ -53,17 +59,22 @@ func runDetailsCommand(cmd *cobra.Command, args []string) {
details.Name = board.Name() details.Name = board.Name()
details.ConfigOptions = []*boardConfigOption{} details.ConfigOptions = []*boardConfigOption{}
options := board.GetConfigOptions() options := board.GetConfigOptions()
t := true
for _, option := range options.Keys() { for _, option := range options.Keys() {
configOption := &boardConfigOption{} configOption := &boardConfigOption{}
configOption.Option = option configOption.Option = option
configOption.OptionLabel = options.Get(option) configOption.OptionLabel = options.Get(option)
selected, hasSelected := fqbn.Configs.GetOk(option)
values := board.GetConfigOptionValues(option) values := board.GetConfigOptionValues(option)
for i, value := range values.Keys() { for i, value := range values.Keys() {
configValue := &boardConfigValue{} configValue := &boardConfigValue{}
if i == 0 { if hasSelected && value == selected {
t := true configValue.Selected = &t
configValue.Default = &t } else if !hasSelected && i == 0 {
configValue.Selected = &t
} }
configValue.Value = value configValue.Value = value
configValue.ValueLabel = values.Get(value) configValue.ValueLabel = values.Get(value)
configOption.Values = append(configOption.Values, configValue) configOption.Values = append(configOption.Values, configValue)
...@@ -89,7 +100,7 @@ type boardConfigOption struct { ...@@ -89,7 +100,7 @@ type boardConfigOption struct {
type boardConfigValue struct { type boardConfigValue struct {
Value string Value string
ValueLabel string ValueLabel string
Default *bool `json:",omitempty"` Selected *bool `json:",omitempty"`
} }
func (details *boardDetails) EmitJSON() string { func (details *boardDetails) EmitJSON() string {
...@@ -103,12 +114,23 @@ func (details *boardDetails) EmitJSON() string { ...@@ -103,12 +114,23 @@ func (details *boardDetails) EmitJSON() string {
func (details *boardDetails) EmitTerminal() string { func (details *boardDetails) EmitTerminal() string {
table := output.NewTable() table := output.NewTable()
table.AddRow("Board name:", output.Red(details.Name)) table.AddRow("Board name:", details.Name)
table.SetColumnWidthMode(1, output.Average) table.SetColumnWidthMode(1, output.Average)
for _, option := range details.ConfigOptions { for _, option := range details.ConfigOptions {
table.AddRow("Option:", option.OptionLabel) table.AddRow()
table.AddRow("Option:",
option.OptionLabel,
"", option.Option)
for _, value := range option.Values { for _, value := range option.Values {
table.AddRow("", value.ValueLabel, option.Option+"="+value.Value) if value.Selected != nil {
table.AddRow("",
output.Green(value.ValueLabel),
output.Green("✔"), output.Green(option.Option+"="+value.Value))
} else {
table.AddRow("",
value.ValueLabel,
"", option.Option+"="+value.Value)
}
} }
} }
return table.Render() return table.Render()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment