Skip to content

Commit 69d6e0a

Browse files
committed
Fixed 'core list' command for platforms installed in the sketchbook
Fix #15
1 parent 412d287 commit 69d6e0a

File tree

7 files changed

+77
-4
lines changed

7 files changed

+77
-4
lines changed

Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

commands/core/list.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ func runListCommand(cmd *cobra.Command, args []string) {
5151
for _, targetPackage := range pm.GetPackages().Packages {
5252
for _, platform := range targetPackage.Platforms {
5353
if platformRelease := platform.GetInstalled(); platformRelease != nil {
54-
if listFlags.updatableOnly && platform.GetLatestRelease() == platformRelease {
55-
continue
54+
if listFlags.updatableOnly {
55+
if latest := platform.GetLatestRelease(); latest == nil || latest == platformRelease {
56+
continue
57+
}
5658
}
5759
res = append(res, platformRelease)
5860
}

common/formatter/output/core_structs.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/arduino/arduino-cli/arduino/cores"
2525
"github.com/gosuri/uitable"
26+
semver "go.bug.st/relaxed-semver"
2627
)
2728

2829
// InstalledPlatformReleases represents an output set of installed platforms.
@@ -51,7 +52,11 @@ func (is InstalledPlatformReleases) String() string {
5152
table.AddRow("ID", "Installed", "Latest", "Name")
5253
sort.Sort(is)
5354
for _, item := range is {
54-
table.AddRow(item.Platform.String(), item.Version, item.Platform.GetLatestRelease().Version, item.Platform.Name)
55+
var latestVersion *semver.Version
56+
if latest := item.Platform.GetLatestRelease(); latest != nil {
57+
latestVersion = latest.Version
58+
}
59+
table.AddRow(item.Platform, item.Version, latestVersion, item.Platform.Name)
5560
}
5661
return fmt.Sprintln(table)
5762
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: go
2+
3+
go:
4+
- 1.10.x
5+
- tip
6+
7+
before_install:
8+
- go get -t -v ./...
9+
10+
script:
11+
- go test -race -coverprofile=coverage.txt -covermode=atomic
12+
13+
after_success:
14+
- bash <(curl -s https://codecov.io/bash)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
3+
# go.bug.st/relaxed-semver [![build status](https://api.travis-ci.org/bugst/relaxed-semver.svg?branch=master)](https://travis-ci.org/bugst/relaxed-semver) [![codecov](https://codecov.io/gh/bugst/relaxed-semver/branch/master/graph/badge.svg)](https://codecov.io/gh/bugst/relaxed-semver)
4+
5+
6+
7+
A library for handling a superset of semantic versioning in golang.
8+
9+
## Documentation and examples
10+
11+
See the godoc here: https://godoc.org/go.bug.st/relaxed-semver
12+
13+
## Semantic versioning specification followed in this library
14+
15+
This library tries to implement the semantic versioning specification [2.0.0](https://semver.org/spec/v2.0.0.html) with an exception: the numeric format `major.minor.patch` like `1.3.2` may be truncated if a number is zero, so:
16+
17+
- `1.2.0` or `1.2.0-beta` may be written as `1.2` or `1.2-beta` respectively
18+
- `1.0.0` or `1.0.0-beta` may be written `1` or `1-beta` respectively
19+
- `0.0.0` may be written as the **empty string**, but `0.0.0-beta` may **not** be written as `-beta`
20+
## Usage
21+
22+
You can parse a semver version string with the `Parse` function that returns a `Version` object that can be used to be compared with other `Version` objects using the `CompareTo`, `LessThan` , `LessThanOrEqual`, `Equal`, `GreaterThan` and `GreaterThanOrEqual` methods.
23+
24+
The `Parse` function returns an `error` if the string does not comply to the above specification. Alternatively the `MustParse` function can be used, it returns only the `Version` object or panics if a parsing error occurs.
25+
26+
## Why Relaxed?
27+
28+
This library allows the use of an even more relaxed semver specification using the `RelaxedVersion` object. It works with the following rules:
29+
30+
- If the parsed string is a valid semver (following the rules above), then the `RelaxedVersion` will behave exactly as a normal `Version` object
31+
- if the parsed string is **not** a valid semver, then the string is kept as-is inside the `RelaxedVersion` object as a custom version string
32+
- when comparing two `RelaxedVersion` the rule is simple: if both are valid semver, the semver rules applies; if both are custom version string they are compared as alphanumeric strings; if one is valid semver and the other is a custom version string the valid semver is always greater
33+
34+
The `RelaxedVersion` object is basically made to allow systems that do not use semver to soft transition to semantic versioning, because it allows an intermediate period where the invalid version is still tolerated.
35+
36+
To parse a `RelaxedVersion` you can use the `ParseRelaxed` function.
37+
38+
## Json parsable
39+
40+
The `Version` and`RelaxedVersion` have the JSON un/marshaler implemented so they can be JSON decoded/encoded.

vendor/go.bug.st/relaxed-semver/relaxed_version.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//
2+
// Copyright 2018 Cristian Maglie. All rights reserved.
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
//
6+
17
package semver
28

39
import "fmt"
@@ -27,6 +33,9 @@ func ParseRelaxed(in string) *RelaxedVersion {
2733
}
2834

2935
func (v *RelaxedVersion) String() string {
36+
if v == nil {
37+
return ""
38+
}
3039
if v.version != nil {
3140
return v.version.String()
3241
}

vendor/go.bug.st/relaxed-semver/version.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type Version struct {
1717
}
1818

1919
func (v *Version) String() string {
20+
if v == nil {
21+
return ""
22+
}
2023
res := string(v.major)
2124
if len(v.minor) > 0 {
2225
res += "." + string(v.minor)

0 commit comments

Comments
 (0)