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
d880e280
Commit
d880e280
authored
Apr 24, 2019
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added helper function to extract parsed version from RPC requests
parent
d53d3c2f
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
91 additions
and
82 deletions
+91
-82
cli/core/args.go
cli/core/args.go
+18
-16
cli/core/args_test.go
cli/core/args_test.go
+2
-2
cli/core/download.go
cli/core/download.go
+4
-4
cli/core/install.go
cli/core/install.go
+2
-2
cli/core/uninstall.go
cli/core/uninstall.go
+2
-2
cli/core/upgrade.go
cli/core/upgrade.go
+2
-2
commands/core/download.go
commands/core/download.go
+3
-8
commands/core/install.go
commands/core/install.go
+3
-8
commands/core/uninstall.go
commands/core/uninstall.go
+1
-2
commands/core/upgrade.go
commands/core/upgrade.go
+5
-12
commands/lib/download.go
commands/lib/download.go
+3
-8
commands/lib/install.go
commands/lib/install.go
+5
-8
commands/lib/uninstall.go
commands/lib/uninstall.go
+5
-8
commands/version.go
commands/version.go
+36
-0
No files found.
cli/core/args.go
View file @
d880e280
...
...
@@ -22,15 +22,20 @@ import (
"os"
"strings"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/common/formatter"
semver
"go.bug.st/relaxed-semver"
)
// parsePlatformReferenceArgs parses a sequence of "packager:arch@version" tokens and returns a platformReference slice.
func
parsePlatformReferenceArgs
(
args
[]
string
)
[]
*
packagemanager
.
PlatformReference
{
ret
:=
[]
*
packagemanager
.
PlatformReference
{}
type
platformReferenceArg
struct
{
Package
string
Architecture
string
Version
string
}
// parsePlatformReferenceArgs parses a sequence of "packager:arch@version" tokens and
// returns a platformReferenceArg slice.
func
parsePlatformReferenceArgs
(
args
[]
string
)
[]
*
platformReferenceArg
{
ret
:=
[]
*
platformReferenceArg
{}
for
_
,
arg
:=
range
args
{
reference
,
err
:=
parsePlatformReferenceArg
(
arg
)
if
err
!=
nil
{
...
...
@@ -42,24 +47,21 @@ func parsePlatformReferenceArgs(args []string) []*packagemanager.PlatformReferen
return
ret
}
func
parsePlatformReferenceArg
(
arg
string
)
(
*
p
ackagemanager
.
PlatformReference
,
error
)
{
func
parsePlatformReferenceArg
(
arg
string
)
(
*
p
latformReferenceArg
,
error
)
{
split
:=
strings
.
SplitN
(
arg
,
"@"
,
2
)
arg
=
split
[
0
]
v
ar
version
*
semver
.
Version
v
ersion
:=
""
if
len
(
split
)
>
1
{
if
ver
,
err
:=
semver
.
Parse
(
split
[
1
]);
err
==
nil
{
version
=
ver
}
else
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
version
=
split
[
1
]
}
split
=
strings
.
Split
(
arg
,
":"
)
if
len
(
split
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"invalid item %s"
,
arg
)
}
return
&
p
ackagemanager
.
PlatformReference
{
Package
:
split
[
0
],
Platform
Architecture
:
split
[
1
],
Platform
Version
:
version
,
return
&
p
latformReferenceArg
{
Package
:
split
[
0
],
Architecture
:
split
[
1
],
Version
:
version
,
},
nil
}
cli/core/args_test.go
View file @
d880e280
...
...
@@ -31,8 +31,8 @@ func TestParsePlatformReferenceArgs(t *testing.T) {
ref
,
err
:=
parsePlatformReferenceArg
(
arg
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
pack
,
ref
.
Package
)
require
.
Equal
(
t
,
arch
,
ref
.
Platform
Architecture
)
require
.
Equal
(
t
,
version
,
ref
.
Platform
Version
)
require
.
Equal
(
t
,
arch
,
ref
.
Architecture
)
require
.
Equal
(
t
,
version
.
String
(),
ref
.
Version
)
}
invalid
:=
func
(
arg
string
)
{
_
,
err
:=
parsePlatformReferenceArg
(
arg
)
...
...
cli/core/download.go
View file @
d880e280
...
...
@@ -48,15 +48,15 @@ func runDownloadCommand(cmd *cobra.Command, args []string) {
logrus
.
Info
(
"Executing `arduino core download`"
)
platformsRefs
:=
parsePlatformReferenceArgs
(
args
)
for
_
,
platformRef
:=
range
platformsRefs
{
for
i
,
platformRef
:=
range
platformsRefs
{
_
,
err
:=
core
.
PlatformDownload
(
context
.
Background
(),
&
rpc
.
PlatformDownloadReq
{
Instance
:
instance
,
PlatformPackage
:
platformRef
.
Package
,
Architecture
:
platformRef
.
Platform
Architecture
,
Version
:
platformRef
.
PlatformVersion
.
String
()
,
Architecture
:
platformRef
.
Architecture
,
Version
:
platformRef
.
Version
,
},
cli
.
OutputProgressBar
())
if
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Error downloading "
+
platformRef
.
String
()
)
formatter
.
PrintError
(
err
,
"Error downloading "
+
args
[
i
]
)
os
.
Exit
(
cli
.
ErrNetwork
)
}
}
...
...
cli/core/install.go
View file @
d880e280
...
...
@@ -54,8 +54,8 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
_
,
err
:=
core
.
PlatformInstall
(
context
.
Background
(),
&
rpc
.
PlatformInstallReq
{
Instance
:
instance
,
PlatformPackage
:
platformRef
.
Package
,
Architecture
:
platformRef
.
Platform
Architecture
,
Version
:
platformRef
.
PlatformVersion
.
String
()
,
Architecture
:
platformRef
.
Architecture
,
Version
:
platformRef
.
Version
,
},
cli
.
OutputProgressBar
(),
cli
.
OutputTaskProgress
())
if
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Error during install"
)
...
...
cli/core/uninstall.go
View file @
d880e280
...
...
@@ -51,8 +51,8 @@ func runUninstallCommand(cmd *cobra.Command, args []string) {
_
,
err
:=
core
.
PlatformUninstall
(
context
.
Background
(),
&
rpc
.
PlatformUninstallReq
{
Instance
:
instance
,
PlatformPackage
:
platformRef
.
Package
,
Architecture
:
platformRef
.
Platform
Architecture
,
Version
:
platformRef
.
PlatformVersion
.
String
()
,
Architecture
:
platformRef
.
Architecture
,
Version
:
platformRef
.
Version
,
},
output
.
NewTaskProgressCB
())
if
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Error during uninstall"
)
...
...
cli/core/upgrade.go
View file @
d880e280
...
...
@@ -53,8 +53,8 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
_
,
err
:=
core
.
PlatformUpgrade
(
context
.
Background
(),
&
rpc
.
PlatformUpgradeReq
{
Instance
:
instance
,
PlatformPackage
:
platformRef
.
Package
,
Architecture
:
platformRef
.
Platform
Architecture
,
Version
:
platformRef
.
PlatformVersion
.
String
()
,
Architecture
:
platformRef
.
Architecture
,
Version
:
platformRef
.
Version
,
},
cli
.
OutputProgressBar
(),
cli
.
OutputTaskProgress
())
if
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Error during upgrade"
)
...
...
commands/core/download.go
View file @
d880e280
...
...
@@ -26,7 +26,6 @@ import (
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/rpc"
semver
"go.bug.st/relaxed-semver"
)
func
PlatformDownload
(
ctx
context
.
Context
,
req
*
rpc
.
PlatformDownloadReq
,
downloadCB
commands
.
DownloadProgressCB
)
(
*
rpc
.
PlatformDownloadResp
,
error
)
{
...
...
@@ -35,13 +34,9 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloa
return
nil
,
errors
.
New
(
"invalid instance"
)
}
var
version
*
semver
.
Version
if
req
.
GetVersion
()
!=
""
{
if
v
,
err
:=
semver
.
Parse
(
req
.
GetVersion
());
err
==
nil
{
version
=
v
}
else
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
version
,
err
:=
commands
.
ParseVersion
(
req
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
platform
,
tools
,
err
:=
pm
.
FindPlatformReleaseDependencies
(
&
packagemanager
.
PlatformReference
{
...
...
commands/core/install.go
View file @
d880e280
...
...
@@ -26,7 +26,6 @@ import (
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/rpc"
semver
"go.bug.st/relaxed-semver"
)
func
PlatformInstall
(
ctx
context
.
Context
,
req
*
rpc
.
PlatformInstallReq
,
...
...
@@ -37,13 +36,9 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq,
return
nil
,
errors
.
New
(
"invalid instance"
)
}
var
version
*
semver
.
Version
if
req
.
GetVersion
()
!=
""
{
if
v
,
err
:=
semver
.
Parse
(
req
.
GetVersion
());
err
==
nil
{
version
=
v
}
else
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
version
,
err
:=
commands
.
ParseVersion
(
req
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
platform
,
tools
,
err
:=
pm
.
FindPlatformReleaseDependencies
(
&
packagemanager
.
PlatformReference
{
...
...
commands/core/uninstall.go
View file @
d880e280
...
...
@@ -26,7 +26,6 @@ import (
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/rpc"
semver
"go.bug.st/relaxed-semver"
)
func
PlatformUninstall
(
ctx
context
.
Context
,
req
*
rpc
.
PlatformUninstallReq
,
taskCB
commands
.
TaskProgressCB
)
(
*
rpc
.
PlatformUninstallResp
,
error
)
{
...
...
@@ -36,7 +35,7 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallReq, taskC
}
// If no version is specified consider the installed
version
,
err
:=
semver
.
Parse
(
req
.
Version
)
version
,
err
:=
commands
.
ParseVersion
(
req
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
...
...
commands/core/upgrade.go
View file @
d880e280
...
...
@@ -25,7 +25,6 @@ import (
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/rpc"
semver
"go.bug.st/relaxed-semver"
)
func
PlatformUpgrade
(
ctx
context
.
Context
,
req
*
rpc
.
PlatformUpgradeReq
,
...
...
@@ -37,26 +36,20 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq,
}
// Extract all PlatformReference to platforms that have updates
var
version
*
semver
.
Version
if
req
.
Version
!=
""
{
if
v
,
err
:=
semver
.
Parse
(
req
.
Version
);
err
==
nil
{
version
=
v
}
else
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
version
,
err
:=
commands
.
ParseVersion
(
req
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
ref
:=
&
packagemanager
.
PlatformReference
{
Package
:
req
.
PlatformPackage
,
PlatformArchitecture
:
req
.
Architecture
,
PlatformVersion
:
version
}
err
:=
upgradePlatform
(
pm
,
ref
,
downloadCB
,
taskCB
)
if
err
!=
nil
{
if
err
:=
upgradePlatform
(
pm
,
ref
,
downloadCB
,
taskCB
);
err
!=
nil
{
return
nil
,
err
}
_
,
err
=
commands
.
Rescan
(
ctx
,
&
rpc
.
RescanReq
{
Instance
:
req
.
Instance
})
if
err
!=
nil
{
if
_
,
err
:=
commands
.
Rescan
(
ctx
,
&
rpc
.
RescanReq
{
Instance
:
req
.
Instance
});
err
!=
nil
{
return
nil
,
err
}
...
...
commands/lib/download.go
View file @
d880e280
...
...
@@ -26,7 +26,6 @@ import (
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/rpc"
"github.com/sirupsen/logrus"
semver
"go.bug.st/relaxed-semver"
)
func
LibraryDownload
(
ctx
context
.
Context
,
req
*
rpc
.
LibraryDownloadReq
,
downloadCB
commands
.
DownloadProgressCB
)
(
*
rpc
.
LibraryDownloadResp
,
error
)
{
...
...
@@ -36,13 +35,9 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadReq, downloadC
logrus
.
Info
(
"Preparing download"
)
var
version
*
semver
.
Version
if
req
.
GetVersion
()
!=
""
{
if
v
,
err
:=
semver
.
Parse
(
req
.
GetVersion
());
err
==
nil
{
version
=
v
}
else
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
version
,
err
:=
commands
.
ParseVersion
(
req
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
ref
:=
&
librariesindex
.
Reference
{
Name
:
req
.
GetName
(),
Version
:
version
}
...
...
commands/lib/install.go
View file @
d880e280
...
...
@@ -25,21 +25,18 @@ import (
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/rpc"
"github.com/sirupsen/logrus"
semver
"go.bug.st/relaxed-semver"
)
func
LibraryInstall
(
ctx
context
.
Context
,
req
*
rpc
.
LibraryInstallReq
,
downloadCB
commands
.
DownloadProgressCB
,
taskCB
commands
.
TaskProgressCB
)
error
{
lm
:=
commands
.
GetLibraryManager
(
req
)
var
version
*
semver
.
Version
if
req
.
GetVersion
()
!=
""
{
if
v
,
err
:=
semver
.
Parse
(
req
.
GetVersion
());
err
==
nil
{
version
=
v
}
else
{
return
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
version
,
err
:=
commands
.
ParseVersion
(
req
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
ref
:=
&
librariesindex
.
Reference
{
Name
:
req
.
GetName
(),
Version
:
version
}
libRelease
:=
lm
.
Index
.
FindRelease
(
ref
)
if
libRelease
==
nil
{
...
...
commands/lib/uninstall.go
View file @
d880e280
...
...
@@ -24,19 +24,16 @@ import (
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/rpc"
semver
"go.bug.st/relaxed-semver"
)
func
LibraryUninstall
(
ctx
context
.
Context
,
req
*
rpc
.
LibraryUninstallReq
,
taskCB
commands
.
TaskProgressCB
)
error
{
lm
:=
commands
.
GetLibraryManager
(
req
)
var
version
*
semver
.
Version
if
req
.
GetVersion
()
!=
""
{
if
v
,
err
:=
semver
.
Parse
(
req
.
GetVersion
());
err
==
nil
{
version
=
v
}
else
{
return
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
version
,
err
:=
commands
.
ParseVersion
(
req
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid version: %s"
,
err
)
}
ref
:=
&
librariesindex
.
Reference
{
Name
:
req
.
GetName
(),
Version
:
version
}
lib
:=
lm
.
FindByReference
(
ref
)
if
lib
==
nil
{
...
...
commands/version.go
0 → 100644
View file @
d880e280
//
// This file is part of arduino-cli.
//
// Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to modify or
// otherwise use the software for commercial activities involving the Arduino
// software without disclosing the source code of your own applications. To purchase
// a commercial license, send an email to license@arduino.cc.
//
package
commands
import
(
semver
"go.bug.st/relaxed-semver"
)
// Versioned is an object that provides a GetVersion() method
type
Versioned
interface
{
GetVersion
()
string
}
// ParseVersion returns the version parsed from an interface that provides
// the GetVersion() method (interface Versioned)
func
ParseVersion
(
req
Versioned
)
(
*
semver
.
Version
,
error
)
{
if
req
.
GetVersion
()
!=
""
{
return
semver
.
Parse
(
req
.
GetVersion
())
}
return
nil
,
nil
}
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