Skip to content

Commit c28cb14

Browse files
cli: compile use feedback result structs
1 parent 4fbdb7e commit c28cb14

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

internal/cli/compile/compile.go

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/arduino/arduino-cli/i18n"
3434
"github.com/arduino/arduino-cli/internal/cli/arguments"
3535
"github.com/arduino/arduino-cli/internal/cli/feedback"
36+
"github.com/arduino/arduino-cli/internal/cli/feedback/result"
3637
"github.com/arduino/arduino-cli/internal/cli/instance"
3738
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3839
"github.com/arduino/arduino-cli/table"
@@ -340,10 +341,14 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
340341

341342
stdIO := stdIORes()
342343
res := &compileResult{
343-
CompilerOut: stdIO.Stdout,
344-
CompilerErr: stdIO.Stderr,
345-
BuilderResult: compileRes,
346-
UploadResult: uploadRes,
344+
CompilerOut: stdIO.Stdout,
345+
CompilerErr: stdIO.Stderr,
346+
BuilderResult: result.NewCompileResponse(compileRes),
347+
UploadResult: struct {
348+
UpdatedUploadPort *result.Port `json:"updated_upload_port,omitempty"`
349+
}{
350+
UpdatedUploadPort: result.NewPort(uploadRes.GetUpdatedUploadPort()),
351+
},
347352
ProfileOut: profileOut,
348353
Success: compileError == nil,
349354
showPropertiesMode: showProperties,
@@ -385,13 +390,15 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
385390
}
386391

387392
type compileResult struct {
388-
CompilerOut string `json:"compiler_out"`
389-
CompilerErr string `json:"compiler_err"`
390-
BuilderResult *rpc.CompileResponse `json:"builder_result"`
391-
UploadResult *rpc.UploadResult `json:"upload_result"`
392-
Success bool `json:"success"`
393-
ProfileOut string `json:"profile_out,omitempty"`
394-
Error string `json:"error,omitempty"`
393+
CompilerOut string `json:"compiler_out"`
394+
CompilerErr string `json:"compiler_err"`
395+
BuilderResult *result.CompileResponse `json:"builder_result"`
396+
UploadResult struct {
397+
UpdatedUploadPort *result.Port `json:"updated_upload_port,omitempty"`
398+
} `json:"upload_result"`
399+
Success bool `json:"success"`
400+
ProfileOut string `json:"profile_out,omitempty"`
401+
Error string `json:"error,omitempty"`
395402

396403
showPropertiesMode arguments.ShowPropertiesMode
397404
hideStats bool
@@ -403,7 +410,7 @@ func (r *compileResult) Data() interface{} {
403410

404411
func (r *compileResult) String() string {
405412
if r.showPropertiesMode != arguments.ShowPropertiesDisabled {
406-
return strings.Join(r.BuilderResult.GetBuildProperties(), fmt.Sprintln())
413+
return strings.Join(r.BuilderResult.BuildProperties, fmt.Sprintln())
407414
}
408415

409416
if r.hideStats {
@@ -419,38 +426,38 @@ func (r *compileResult) String() string {
419426
if r.CompilerOut != "" || r.CompilerErr != "" {
420427
res += fmt.Sprintln()
421428
}
422-
if len(build.GetUsedLibraries()) > 0 {
429+
if len(build.UsedLibraries) > 0 {
423430
libraries := table.New()
424431
libraries.SetHeader(
425432
table.NewCell(tr("Used library"), titleColor),
426433
table.NewCell(tr("Version"), titleColor),
427434
table.NewCell(tr("Path"), pathColor))
428-
for _, l := range build.GetUsedLibraries() {
435+
for _, l := range build.UsedLibraries {
429436
libraries.AddRow(
430-
table.NewCell(l.GetName(), nameColor),
431-
l.GetVersion(),
432-
table.NewCell(l.GetInstallDir(), pathColor))
437+
table.NewCell(l.Name, nameColor),
438+
l.Version,
439+
table.NewCell(l.InstallDir, pathColor))
433440
}
434441
res += fmt.Sprintln(libraries.Render())
435442
}
436443

437-
if boardPlatform := build.GetBoardPlatform(); boardPlatform != nil {
444+
if boardPlatform := build.BoardPlatform; boardPlatform != nil {
438445
platforms := table.New()
439446
platforms.SetHeader(
440447
table.NewCell(tr("Used platform"), titleColor),
441448
table.NewCell(tr("Version"), titleColor),
442449
table.NewCell(tr("Path"), pathColor))
443450
platforms.AddRow(
444-
table.NewCell(boardPlatform.GetId(), nameColor),
445-
boardPlatform.GetVersion(),
446-
table.NewCell(boardPlatform.GetInstallDir(), pathColor))
447-
if buildPlatform := build.GetBuildPlatform(); buildPlatform != nil &&
451+
table.NewCell(boardPlatform.Id, nameColor),
452+
boardPlatform.Version,
453+
table.NewCell(boardPlatform.InstallDir, pathColor))
454+
if buildPlatform := build.BuildPlatform; buildPlatform != nil &&
448455
buildPlatform.Id != boardPlatform.Id &&
449456
buildPlatform.Version != boardPlatform.Version {
450457
platforms.AddRow(
451-
table.NewCell(buildPlatform.GetId(), nameColor),
452-
buildPlatform.GetVersion(),
453-
table.NewCell(buildPlatform.GetInstallDir(), pathColor))
458+
table.NewCell(buildPlatform.Id, nameColor),
459+
buildPlatform.Version,
460+
table.NewCell(buildPlatform.InstallDir, pathColor))
454461
}
455462
res += fmt.Sprintln(platforms.Render())
456463
}

internal/cli/feedback/result/rpc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,8 @@ func NewCompileResponse(c *rpc.CompileResponse) *CompileResponse {
842842
BuildPath: c.GetBuildPath(),
843843
UsedLibraries: usedLibs,
844844
ExecutableSectionsSize: executableSectionsSizes,
845-
BoardPlatform: &InstalledPlatformReference{},
846-
BuildPlatform: &InstalledPlatformReference{},
845+
BoardPlatform: NewInstalledPlatformReference(c.GetBoardPlatform()),
846+
BuildPlatform: NewInstalledPlatformReference(c.GetBuildPlatform()),
847847
BuildProperties: c.GetBuildProperties(),
848848
}
849849
}

0 commit comments

Comments
 (0)