Commit 69d6e0ab authored by Cristian Maglie's avatar Cristian Maglie

Fixed 'core list' command for platforms installed in the sketchbook

Fix #15
parent 412d2877
...@@ -351,7 +351,7 @@ ...@@ -351,7 +351,7 @@
branch = "master" branch = "master"
name = "go.bug.st/relaxed-semver" name = "go.bug.st/relaxed-semver"
packages = ["."] packages = ["."]
revision = "8f3ea8a5f043c095e6a3f27021be84e28551785b" revision = "634f2c8a7dad58007b2539ce542ba69f1e50893c"
[[projects]] [[projects]]
branch = "master" branch = "master"
......
...@@ -51,8 +51,10 @@ func runListCommand(cmd *cobra.Command, args []string) { ...@@ -51,8 +51,10 @@ func runListCommand(cmd *cobra.Command, args []string) {
for _, targetPackage := range pm.GetPackages().Packages { for _, targetPackage := range pm.GetPackages().Packages {
for _, platform := range targetPackage.Platforms { for _, platform := range targetPackage.Platforms {
if platformRelease := platform.GetInstalled(); platformRelease != nil { if platformRelease := platform.GetInstalled(); platformRelease != nil {
if listFlags.updatableOnly && platform.GetLatestRelease() == platformRelease { if listFlags.updatableOnly {
continue if latest := platform.GetLatestRelease(); latest == nil || latest == platformRelease {
continue
}
} }
res = append(res, platformRelease) res = append(res, platformRelease)
} }
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"github.com/arduino/arduino-cli/arduino/cores" "github.com/arduino/arduino-cli/arduino/cores"
"github.com/gosuri/uitable" "github.com/gosuri/uitable"
semver "go.bug.st/relaxed-semver"
) )
// InstalledPlatformReleases represents an output set of installed platforms. // InstalledPlatformReleases represents an output set of installed platforms.
...@@ -51,7 +52,11 @@ func (is InstalledPlatformReleases) String() string { ...@@ -51,7 +52,11 @@ func (is InstalledPlatformReleases) String() string {
table.AddRow("ID", "Installed", "Latest", "Name") table.AddRow("ID", "Installed", "Latest", "Name")
sort.Sort(is) sort.Sort(is)
for _, item := range is { for _, item := range is {
table.AddRow(item.Platform.String(), item.Version, item.Platform.GetLatestRelease().Version, item.Platform.Name) var latestVersion *semver.Version
if latest := item.Platform.GetLatestRelease(); latest != nil {
latestVersion = latest.Version
}
table.AddRow(item.Platform, item.Version, latestVersion, item.Platform.Name)
} }
return fmt.Sprintln(table) return fmt.Sprintln(table)
} }
......
language: go
go:
- 1.10.x
- tip
before_install:
- go get -t -v ./...
script:
- go test -race -coverprofile=coverage.txt -covermode=atomic
after_success:
- bash <(curl -s https://codecov.io/bash)
# 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)
A library for handling a superset of semantic versioning in golang.
## Documentation and examples
See the godoc here: https://godoc.org/go.bug.st/relaxed-semver
## Semantic versioning specification followed in this library
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:
- `1.2.0` or `1.2.0-beta` may be written as `1.2` or `1.2-beta` respectively
- `1.0.0` or `1.0.0-beta` may be written `1` or `1-beta` respectively
- `0.0.0` may be written as the **empty string**, but `0.0.0-beta` may **not** be written as `-beta`
## Usage
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.
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.
## Why Relaxed?
This library allows the use of an even more relaxed semver specification using the `RelaxedVersion` object. It works with the following rules:
- If the parsed string is a valid semver (following the rules above), then the `RelaxedVersion` will behave exactly as a normal `Version` object
- 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
- 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
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.
To parse a `RelaxedVersion` you can use the `ParseRelaxed` function.
## Json parsable
The `Version` and`RelaxedVersion` have the JSON un/marshaler implemented so they can be JSON decoded/encoded.
\ No newline at end of file
//
// Copyright 2018 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package semver package semver
import "fmt" import "fmt"
...@@ -27,6 +33,9 @@ func ParseRelaxed(in string) *RelaxedVersion { ...@@ -27,6 +33,9 @@ func ParseRelaxed(in string) *RelaxedVersion {
} }
func (v *RelaxedVersion) String() string { func (v *RelaxedVersion) String() string {
if v == nil {
return ""
}
if v.version != nil { if v.version != nil {
return v.version.String() return v.version.String()
} }
......
...@@ -17,6 +17,9 @@ type Version struct { ...@@ -17,6 +17,9 @@ type Version struct {
} }
func (v *Version) String() string { func (v *Version) String() string {
if v == nil {
return ""
}
res := string(v.major) res := string(v.major)
if len(v.minor) > 0 { if len(v.minor) > 0 {
res += "." + string(v.minor) res += "." + string(v.minor)
......
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