Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
f8e52e2e
Commit
f8e52e2e
authored
Sep 24, 2018
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-enabled json output for 'core list' command
Fix #39
parent
5f2d04f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
39 deletions
+65
-39
commands/core/list.go
commands/core/list.go
+14
-4
commands/core/search.go
commands/core/search.go
+14
-4
common/formatter/output/core_structs.go
common/formatter/output/core_structs.go
+37
-31
No files found.
commands/core/list.go
View file @
f8e52e2e
...
...
@@ -23,6 +23,7 @@ import (
"github.com/arduino/arduino-cli/common/formatter/output"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
semver
"go.bug.st/relaxed-semver"
)
func
initListCommand
()
*
cobra
.
Command
{
...
...
@@ -47,7 +48,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
pm
:=
commands
.
InitPackageManager
()
res
:=
output
.
InstalledPlatformReleases
{}
installed
:=
[]
*
output
.
InstalledPlatform
{}
for
_
,
targetPackage
:=
range
pm
.
GetPackages
()
.
Packages
{
for
_
,
platform
:=
range
targetPackage
.
Platforms
{
if
platformRelease
:=
pm
.
GetInstalledPlatformRelease
(
platform
);
platformRelease
!=
nil
{
...
...
@@ -56,12 +57,21 @@ func runListCommand(cmd *cobra.Command, args []string) {
continue
}
}
res
=
append
(
res
,
platformRelease
)
var
latestVersion
*
semver
.
Version
if
latest
:=
platformRelease
.
Platform
.
GetLatestRelease
();
latest
!=
nil
{
latestVersion
=
latest
.
Version
}
installed
=
append
(
installed
,
&
output
.
InstalledPlatform
{
ID
:
platformRelease
.
String
(),
Installed
:
platformRelease
.
Version
,
Latest
:
latestVersion
,
Name
:
platformRelease
.
Platform
.
Name
,
})
}
}
}
if
len
(
res
)
>
0
{
formatter
.
Print
(
res
)
if
len
(
installed
)
>
0
{
formatter
.
Print
(
output
.
InstalledPlatforms
{
Platforms
:
installed
}
)
}
}
commands/core/search.go
View file @
f8e52e2e
...
...
@@ -21,9 +21,11 @@ import (
"regexp"
"strings"
"github.com/arduino/arduino-cli/common/formatter/output"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/common/formatter/output"
"github.com/spf13/cobra"
)
...
...
@@ -40,13 +42,13 @@ func initSearchCommand() *cobra.Command {
}
func
runSearchCommand
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
pm
:=
commands
.
InitPackageManager
()
pm
:=
commands
.
InitPackageManager
WithoutBundles
()
search
:=
strings
.
ToLower
(
strings
.
Join
(
args
,
" "
))
formatter
.
Print
(
"Searching for platforms matching '"
+
search
+
"'"
)
formatter
.
Print
(
""
)
res
:=
output
.
PlatformReleases
{}
res
:=
[]
*
cores
.
PlatformRelease
{}
if
isUsb
,
_
:=
regexp
.
MatchString
(
"[0-9a-f]{4}:[0-9a-f]{4}"
,
search
);
isUsb
{
vid
,
pid
:=
search
[
:
4
],
search
[
5
:
]
res
=
pm
.
FindPlatformReleaseProvidingBoardsWithVidPid
(
vid
,
pid
)
...
...
@@ -77,6 +79,14 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
if
len
(
res
)
==
0
{
formatter
.
Print
(
"No platforms matching your search"
)
}
else
{
formatter
.
Print
(
res
)
out
:=
[]
*
output
.
SearchedPlatform
{}
for
_
,
platformRelease
:=
range
res
{
out
=
append
(
out
,
&
output
.
SearchedPlatform
{
ID
:
platformRelease
.
Platform
.
String
(),
Name
:
platformRelease
.
Platform
.
Name
,
Version
:
platformRelease
.
Version
,
})
}
formatter
.
Print
(
output
.
SearchedPlatforms
{
Platforms
:
out
})
}
}
common/formatter/output/core_structs.go
View file @
f8e52e2e
...
...
@@ -21,59 +21,65 @@ import (
"fmt"
"sort"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/gosuri/uitable"
semver
"go.bug.st/relaxed-semver"
)
// InstalledPlatformReleases represents an output set of installed platforms.
type
InstalledPlatformReleases
[]
*
cores
.
PlatformRelease
func
(
is
InstalledPlatformReleases
)
Len
()
int
{
return
len
(
is
)
}
func
(
is
InstalledPlatformReleases
)
Swap
(
i
,
j
int
)
{
is
[
i
],
is
[
j
]
=
is
[
j
],
is
[
i
]
}
func
(
is
InstalledPlatformReleases
)
Less
(
i
,
j
int
)
bool
{
return
is
[
i
]
.
Platform
.
String
()
<
is
[
j
]
.
Platform
.
String
()
// InstalledPlatforms represents an output of a set of installed platforms.
type
InstalledPlatforms
struct
{
Platforms
[]
*
InstalledPlatform
}
// PlatformReleases represents an output set of tools of platforms.
type
PlatformReleases
[]
*
cores
.
PlatformRelease
// InstalledPlatform represents an output of an installed plaform.
type
InstalledPlatform
struct
{
ID
string
Installed
*
semver
.
Version
Latest
*
semver
.
Version
Name
string
}
func
(
is
PlatformReleases
)
Len
()
int
{
return
len
(
is
)
}
func
(
is
PlatformReleases
)
Swap
(
i
,
j
int
)
{
is
[
i
],
is
[
j
]
=
is
[
j
],
is
[
i
]
}
func
(
is
PlatformReleases
)
Less
(
i
,
j
int
)
bool
{
return
is
[
i
]
.
Platform
.
String
()
<
is
[
j
]
.
Platform
.
String
()
func
(
is
InstalledPlatforms
)
less
(
i
,
j
int
)
bool
{
return
is
.
Platforms
[
i
]
.
ID
<
is
.
Platforms
[
j
]
.
ID
}
func
(
is
InstalledPlatform
Release
s
)
String
()
string
{
func
(
is
InstalledPlatforms
)
String
()
string
{
table
:=
uitable
.
New
()
table
.
MaxColWidth
=
100
table
.
Wrap
=
true
table
.
AddRow
(
"ID"
,
"Installed"
,
"Latest"
,
"Name"
)
sort
.
Sort
(
is
)
for
_
,
item
:=
range
is
{
var
latestVersion
*
semver
.
Version
if
latest
:=
item
.
Platform
.
GetLatestRelease
();
latest
!=
nil
{
latestVersion
=
latest
.
Version
}
table
.
AddRow
(
item
.
Platform
,
item
.
Version
,
latestVersion
,
item
.
Platform
.
Name
)
sort
.
Slice
(
is
.
Platforms
,
is
.
less
)
for
_
,
item
:=
range
is
.
Platforms
{
table
.
AddRow
(
item
.
ID
,
item
.
Installed
,
item
.
Latest
,
item
.
Name
)
}
return
fmt
.
Sprintln
(
table
)
}
func
(
is
PlatformReleases
)
String
()
string
{
// SearchedPlatforms represents an output of a set of searched platforms
type
SearchedPlatforms
struct
{
Platforms
[]
*
SearchedPlatform
}
func
(
is
SearchedPlatforms
)
less
(
i
,
j
int
)
bool
{
return
is
.
Platforms
[
i
]
.
ID
<
is
.
Platforms
[
j
]
.
ID
}
// SearchedPlatform represents an output of a searched platform
type
SearchedPlatform
struct
{
ID
string
Version
*
semver
.
Version
Name
string
}
func
(
is
SearchedPlatforms
)
String
()
string
{
table
:=
uitable
.
New
()
table
.
MaxColWidth
=
100
table
.
Wrap
=
true
table
.
AddRow
(
"ID"
,
"Version"
,
"Installed"
,
"Name"
)
sort
.
Sort
(
is
)
for
_
,
item
:=
range
is
{
installed
:=
"No"
if
item
.
InstallDir
!=
nil
{
installed
=
"Yes"
}
table
.
AddRow
(
item
.
Platform
.
String
(),
item
.
Version
,
installed
,
item
.
Platform
.
Name
)
sort
.
Slice
(
is
.
Platforms
,
is
.
less
)
table
.
AddRow
(
"ID"
,
"Version"
,
"Name"
)
for
_
,
item
:=
range
is
.
Platforms
{
table
.
AddRow
(
item
.
ID
,
item
.
Version
,
item
.
Name
)
}
return
fmt
.
Sprintln
(
table
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment