Skip to content

Commit bd8709d

Browse files
committed
Implemented --show-properties in 'board details'
1 parent 0489a0a commit bd8709d

File tree

5 files changed

+208
-169
lines changed

5 files changed

+208
-169
lines changed

Diff for: commands/board/details.go

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
5555
Properties: p.AsMap(),
5656
})
5757
}
58+
for _, k := range boardProperties.Keys() {
59+
v := boardProperties.Get(k)
60+
details.BuildProperties = append(details.BuildProperties, k+"="+v)
61+
}
5862

5963
details.DebuggingSupported = boardProperties.ContainsKey("debug.executable") ||
6064
boardPlatform.Properties.ContainsKey("debug.executable") ||

Diff for: internal/cli/board/details.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/arduino/arduino-cli/commands/board"
2424
"github.com/arduino/arduino-cli/internal/cli/arguments"
25+
"github.com/arduino/arduino-cli/internal/cli/compile"
2526
"github.com/arduino/arduino-cli/internal/cli/feedback"
2627
"github.com/arduino/arduino-cli/internal/cli/instance"
2728
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -35,43 +36,52 @@ func initDetailsCommand() *cobra.Command {
3536
var showFullDetails bool
3637
var listProgrammers bool
3738
var fqbn arguments.Fqbn
39+
var showProperties arguments.ShowProperties
3840
var detailsCommand = &cobra.Command{
3941
Use: fmt.Sprintf("details -b <%s>", tr("FQBN")),
4042
Short: tr("Print details about a board."),
4143
Long: tr("Show information about a board, in particular if the board has options to be specified in the FQBN."),
4244
Example: " " + os.Args[0] + " board details -b arduino:avr:nano",
4345
Args: cobra.NoArgs,
4446
Run: func(cmd *cobra.Command, args []string) {
45-
runDetailsCommand(fqbn.String(), showFullDetails, listProgrammers)
47+
runDetailsCommand(fqbn.String(), showFullDetails, listProgrammers, showProperties)
4648
},
4749
}
4850

4951
fqbn.AddToCommand(detailsCommand)
5052
detailsCommand.Flags().BoolVarP(&showFullDetails, "full", "f", false, tr("Show full board details"))
5153
detailsCommand.Flags().BoolVarP(&listProgrammers, "list-programmers", "", false, tr("Show list of available programmers"))
5254
detailsCommand.MarkFlagRequired("fqbn")
53-
55+
showProperties.AddToCommand(detailsCommand)
5456
return detailsCommand
5557
}
5658

57-
func runDetailsCommand(fqbn string, showFullDetails, listProgrammers bool) {
59+
func runDetailsCommand(fqbn string, showFullDetails, listProgrammers bool, showProperties arguments.ShowProperties) {
5860
inst := instance.CreateAndInit()
5961

6062
logrus.Info("Executing `arduino-cli board details`")
6163

64+
showPropertiesMode, err := showProperties.Get()
65+
if err != nil {
66+
feedback.Fatal(err.Error(), feedback.ErrBadArgument)
67+
}
6268
res, err := board.Details(context.Background(), &rpc.BoardDetailsRequest{
6369
Instance: inst,
6470
Fqbn: fqbn,
6571
})
66-
6772
if err != nil {
6873
feedback.Fatal(tr("Error getting board details: %v", err), feedback.ErrGeneric)
6974
}
7075

76+
if showPropertiesMode == arguments.ShowPropertiesExpanded {
77+
res.BuildProperties, _ = compile.ExpandBuildProperties(res.GetBuildProperties())
78+
}
79+
7180
feedback.PrintResult(detailsResult{
7281
details: res,
7382
listProgrammers: listProgrammers,
7483
showFullDetails: showFullDetails,
84+
showProperties: showPropertiesMode != arguments.ShowPropertiesDisabled,
7585
})
7686
}
7787

@@ -81,6 +91,7 @@ type detailsResult struct {
8191
details *rpc.BoardDetailsResponse
8292
listProgrammers bool
8393
showFullDetails bool
94+
showProperties bool
8495
}
8596

8697
func (dr detailsResult) Data() interface{} {
@@ -90,6 +101,14 @@ func (dr detailsResult) Data() interface{} {
90101
func (dr detailsResult) String() string {
91102
details := dr.details
92103

104+
if dr.showProperties {
105+
res := ""
106+
for _, prop := range details.GetBuildProperties() {
107+
res += fmt.Sprintln(prop)
108+
}
109+
return res
110+
}
111+
93112
if dr.listProgrammers {
94113
t := table.New()
95114
t.AddRow(tr("Id"), tr("Programmer name"))

Diff for: internal/cli/compile/compile.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -365,21 +365,24 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
365365
feedback.FatalResult(res, feedback.ErrGeneric)
366366
}
367367
if showProperties == arguments.ShowPropertiesExpanded {
368-
expandPropertiesInResult(res)
368+
res.BuilderResult.BuildProperties, _ = ExpandBuildProperties(res.BuilderResult.GetBuildProperties())
369+
// ignore error, it should never fail
369370
}
370371
feedback.PrintResult(res)
371372
}
372373

373-
func expandPropertiesInResult(res *compileResult) {
374-
expanded, err := properties.LoadFromSlice(res.BuilderResult.GetBuildProperties())
374+
// ExpandBuildProperties expands the build properties placeholders in the slice of properties.
375+
func ExpandBuildProperties(props []string) ([]string, error) {
376+
expanded, err := properties.LoadFromSlice(props)
375377
if err != nil {
376-
res.Error = tr(err.Error())
378+
return nil, err
377379
}
378-
expandedSlice := make([]string, expanded.Size())
379-
for i, k := range expanded.Keys() {
380-
expandedSlice[i] = strings.Join([]string{k, expanded.ExpandPropsInString(expanded.Get(k))}, "=")
380+
expandedProps := []string{}
381+
for _, k := range expanded.Keys() {
382+
v := expanded.Get(k)
383+
expandedProps = append(expandedProps, k+"="+expanded.ExpandPropsInString(v))
381384
}
382-
res.BuilderResult.BuildProperties = expandedSlice
385+
return expandedProps, nil
383386
}
384387

385388
type compileResult struct {

0 commit comments

Comments
 (0)