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 (
"encoding/json"
"os"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/output"
"github.com/arduino/arduino-cli/commands"
......@@ -42,8 +43,13 @@ func initDetailsCommand() *cobra.Command {
func runDetailsCommand(cmd *cobra.Command, args []string) {
pm := commands.InitPackageManager()
fqbnIn := args[0]
board, err := pm.FindBoardWithFQBN(fqbnIn)
fqbn, err := cores.ParseFQBN(args[0])
if err != nil {
formatter.PrintError(err, "Error parsing fqbn")
os.Exit(commands.ErrBadArgument)
}
_, _, board, _, _, err := pm.ResolveFQBN(fqbn)
if err != nil {
formatter.PrintError(err, "Error loading board data")
os.Exit(commands.ErrBadArgument)
......@@ -53,17 +59,22 @@ func runDetailsCommand(cmd *cobra.Command, args []string) {
details.Name = board.Name()
details.ConfigOptions = []*boardConfigOption{}
options := board.GetConfigOptions()
t := true
for _, option := range options.Keys() {
configOption := &boardConfigOption{}
configOption.Option = option
configOption.OptionLabel = options.Get(option)
selected, hasSelected := fqbn.Configs.GetOk(option)
values := board.GetConfigOptionValues(option)
for i, value := range values.Keys() {
configValue := &boardConfigValue{}
if i == 0 {
t := true
configValue.Default = &t
if hasSelected && value == selected {
configValue.Selected = &t
} else if !hasSelected && i == 0 {
configValue.Selected = &t
}
configValue.Value = value
configValue.ValueLabel = values.Get(value)
configOption.Values = append(configOption.Values, configValue)
......@@ -89,7 +100,7 @@ type boardConfigOption struct {
type boardConfigValue struct {
Value string
ValueLabel string
Default *bool `json:",omitempty"`
Selected *bool `json:",omitempty"`
}
func (details *boardDetails) EmitJSON() string {
......@@ -103,12 +114,23 @@ func (details *boardDetails) EmitJSON() string {
func (details *boardDetails) EmitTerminal() string {
table := output.NewTable()
table.AddRow("Board name:", output.Red(details.Name))
table.AddRow("Board name:", details.Name)
table.SetColumnWidthMode(1, output.Average)
for _, option := range details.ConfigOptions {
table.AddRow("Option:", option.OptionLabel)
table.AddRow()
table.AddRow("Option:",
option.OptionLabel,
"", option.Option)
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()
......
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