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
24ac0405
Commit
24ac0405
authored
Apr 30, 2024
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass down context in all places where it's needed
parent
240c8b3e
Changes
51
Hide whitespace changes
Inline
Side-by-side
Showing
51 changed files
with
161 additions
and
182 deletions
+161
-182
commands/instances.go
commands/instances.go
+3
-5
internal/arduino/builder/builder.go
internal/arduino/builder/builder.go
+4
-0
internal/arduino/builder/internal/detector/detector.go
internal/arduino/builder/internal/detector/detector.go
+8
-4
internal/arduino/builder/internal/preprocessor/arduino_preprocessor.go
...ino/builder/internal/preprocessor/arduino_preprocessor.go
+3
-2
internal/arduino/builder/internal/preprocessor/ctags.go
internal/arduino/builder/internal/preprocessor/ctags.go
+5
-4
internal/arduino/builder/internal/preprocessor/gcc.go
internal/arduino/builder/internal/preprocessor/gcc.go
+2
-1
internal/arduino/builder/preprocess_sketch.go
internal/arduino/builder/preprocess_sketch.go
+1
-0
internal/arduino/cores/packagemanager/profiles.go
internal/arduino/cores/packagemanager/profiles.go
+7
-6
internal/arduino/resources/index.go
internal/arduino/resources/index.go
+2
-2
internal/arduino/resources/resources_test.go
internal/arduino/resources/resources_test.go
+4
-2
internal/cli/arguments/completion.go
internal/cli/arguments/completion.go
+3
-3
internal/cli/arguments/fqbn.go
internal/cli/arguments/fqbn.go
+4
-4
internal/cli/arguments/port.go
internal/cli/arguments/port.go
+8
-8
internal/cli/arguments/profiles.go
internal/cli/arguments/profiles.go
+1
-3
internal/cli/arguments/programmer.go
internal/cli/arguments/programmer.go
+3
-3
internal/cli/board/attach.go
internal/cli/board/attach.go
+4
-4
internal/cli/board/details.go
internal/cli/board/details.go
+3
-4
internal/cli/board/list.go
internal/cli/board/list.go
+6
-7
internal/cli/board/listall.go
internal/cli/board/listall.go
+3
-4
internal/cli/board/search.go
internal/cli/board/search.go
+3
-4
internal/cli/burnbootloader/burnbootloader.go
internal/cli/burnbootloader/burnbootloader.go
+4
-5
internal/cli/cache/clean.go
internal/cli/cache/clean.go
+3
-3
internal/cli/cli.go
internal/cli/cli.go
+1
-1
internal/cli/compile/compile.go
internal/cli/compile/compile.go
+3
-4
internal/cli/config/get.go
internal/cli/config/get.go
+2
-3
internal/cli/core/download.go
internal/cli/core/download.go
+3
-4
internal/cli/core/install.go
internal/cli/core/install.go
+3
-4
internal/cli/core/list.go
internal/cli/core/list.go
+2
-3
internal/cli/core/search.go
internal/cli/core/search.go
+2
-3
internal/cli/core/uninstall.go
internal/cli/core/uninstall.go
+3
-4
internal/cli/core/update_index.go
internal/cli/core/update_index.go
+2
-3
internal/cli/core/upgrade.go
internal/cli/core/upgrade.go
+2
-3
internal/cli/debug/debug.go
internal/cli/debug/debug.go
+6
-7
internal/cli/debug/debug_check.go
internal/cli/debug/debug_check.go
+5
-6
internal/cli/lib/check_deps.go
internal/cli/lib/check_deps.go
+3
-4
internal/cli/lib/download.go
internal/cli/lib/download.go
+3
-4
internal/cli/lib/examples.go
internal/cli/lib/examples.go
+3
-4
internal/cli/lib/install.go
internal/cli/lib/install.go
+3
-4
internal/cli/lib/list.go
internal/cli/lib/list.go
+1
-1
internal/cli/lib/search.go
internal/cli/lib/search.go
+2
-3
internal/cli/lib/uninstall.go
internal/cli/lib/uninstall.go
+3
-4
internal/cli/lib/update_index.go
internal/cli/lib/update_index.go
+2
-3
internal/cli/lib/upgrade.go
internal/cli/lib/upgrade.go
+2
-3
internal/cli/monitor/monitor.go
internal/cli/monitor/monitor.go
+4
-5
internal/cli/outdated/outdated.go
internal/cli/outdated/outdated.go
+2
-3
internal/cli/sketch/archive.go
internal/cli/sketch/archive.go
+2
-3
internal/cli/sketch/new.go
internal/cli/sketch/new.go
+2
-3
internal/cli/update/update.go
internal/cli/update/update.go
+2
-3
internal/cli/upgrade/upgrade.go
internal/cli/upgrade/upgrade.go
+2
-3
internal/cli/upload/upload.go
internal/cli/upload/upload.go
+4
-6
internal/cli/version/version.go
internal/cli/version/version.go
+3
-3
No files found.
commands/instances.go
View file @
24ac0405
...
...
@@ -251,7 +251,7 @@ func (s *arduinoCoreServerImpl) Init(req *rpc.InitRequest, stream rpc.ArduinoCor
}
}
else
{
// Load platforms from profile
errs
:=
pmb
.
LoadHardwareForProfile
(
profile
,
true
,
downloadCallback
,
taskCallback
,
s
.
settings
)
errs
:=
pmb
.
LoadHardwareForProfile
(
ctx
,
profile
,
true
,
downloadCallback
,
taskCallback
,
s
.
settings
)
for
_
,
err
:=
range
errs
{
s
:=
&
cmderrors
.
PlatformLoadingError
{
Cause
:
err
}
responseError
(
s
.
GRPCStatus
())
...
...
@@ -497,13 +497,11 @@ func (s *arduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd
}
// Perform index update
// TODO: pass context
// ctx := stream.Context()
config
,
err
:=
s
.
settings
.
DownloaderConfig
()
if
err
!=
nil
{
return
err
}
if
err
:=
globals
.
LibrariesIndexResource
.
Download
(
indexDir
,
downloadCB
,
config
);
err
!=
nil
{
if
err
:=
globals
.
LibrariesIndexResource
.
Download
(
stream
.
Context
(),
indexDir
,
downloadCB
,
config
);
err
!=
nil
{
resultCB
(
rpc
.
IndexUpdateReport_STATUS_FAILED
)
return
err
}
...
...
@@ -621,7 +619,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
indexResource
.
SignatureURL
,
_
=
url
.
Parse
(
u
)
// should not fail because we already parsed it
indexResource
.
SignatureURL
.
Path
+=
".sig"
}
if
err
:=
indexResource
.
Download
(
indexpath
,
downloadCB
,
config
);
err
!=
nil
{
if
err
:=
indexResource
.
Download
(
stream
.
Context
(),
indexpath
,
downloadCB
,
config
);
err
!=
nil
{
failed
=
true
result
.
UpdatedIndexes
=
append
(
result
.
GetUpdatedIndexes
(),
report
(
URL
,
rpc
.
IndexUpdateReport_STATUS_FAILED
))
}
else
{
...
...
internal/arduino/builder/builder.go
View file @
24ac0405
...
...
@@ -44,6 +44,8 @@ var ErrSketchCannotBeLocatedInBuildPath = errors.New("sketch cannot be located i
// Builder is a Sketch builder.
type
Builder
struct
{
ctx
context
.
Context
sketch
*
sketch
.
Sketch
buildProperties
*
properties
.
Map
...
...
@@ -198,6 +200,7 @@ func NewBuilder(
diagnosticStore
:=
diagnostics
.
NewStore
()
b
:=
&
Builder
{
ctx
:
ctx
,
sketch
:
sk
,
buildProperties
:
buildProperties
,
buildPath
:
buildPath
,
...
...
@@ -305,6 +308,7 @@ func (b *Builder) preprocess() error {
b
.
logIfVerbose
(
false
,
tr
(
"Detecting libraries used..."
))
err
:=
b
.
libsDetector
.
FindIncludes
(
b
.
ctx
,
b
.
buildPath
,
b
.
buildProperties
.
GetPath
(
"build.core.path"
),
b
.
buildProperties
.
GetPath
(
"build.variant.path"
),
...
...
internal/arduino/builder/internal/detector/detector.go
View file @
24ac0405
...
...
@@ -17,6 +17,7 @@ package detector
import
(
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
...
...
@@ -196,6 +197,7 @@ func (l *SketchLibrariesDetector) appendIncludeFolder(
// FindIncludes todo
func
(
l
*
SketchLibrariesDetector
)
FindIncludes
(
ctx
context
.
Context
,
buildPath
*
paths
.
Path
,
buildCorePath
*
paths
.
Path
,
buildVariantPath
*
paths
.
Path
,
...
...
@@ -205,7 +207,7 @@ func (l *SketchLibrariesDetector) FindIncludes(
buildProperties
*
properties
.
Map
,
platformArch
string
,
)
error
{
err
:=
l
.
findIncludes
(
buildPath
,
buildCorePath
,
buildVariantPath
,
sketchBuildPath
,
sketch
,
librariesBuildPath
,
buildProperties
,
platformArch
)
err
:=
l
.
findIncludes
(
ctx
,
buildPath
,
buildCorePath
,
buildVariantPath
,
sketchBuildPath
,
sketch
,
librariesBuildPath
,
buildProperties
,
platformArch
)
if
err
!=
nil
&&
l
.
onlyUpdateCompilationDatabase
{
l
.
logger
.
Info
(
fmt
.
Sprintf
(
...
...
@@ -220,6 +222,7 @@ func (l *SketchLibrariesDetector) FindIncludes(
}
func
(
l
*
SketchLibrariesDetector
)
findIncludes
(
ctx
context
.
Context
,
buildPath
*
paths
.
Path
,
buildCorePath
*
paths
.
Path
,
buildVariantPath
*
paths
.
Path
,
...
...
@@ -269,7 +272,7 @@ func (l *SketchLibrariesDetector) findIncludes(
}
for
!
sourceFileQueue
.
empty
()
{
err
:=
l
.
findIncludesUntilDone
(
cache
,
sourceFileQueue
,
buildProperties
,
sketchBuildPath
,
librariesBuildPath
,
platformArch
)
err
:=
l
.
findIncludesUntilDone
(
c
tx
,
c
ache
,
sourceFileQueue
,
buildProperties
,
sketchBuildPath
,
librariesBuildPath
,
platformArch
)
if
err
!=
nil
{
cachePath
.
Remove
()
return
err
...
...
@@ -297,6 +300,7 @@ func (l *SketchLibrariesDetector) findIncludes(
}
func
(
l
*
SketchLibrariesDetector
)
findIncludesUntilDone
(
ctx
context
.
Context
,
cache
*
includeCache
,
sourceFileQueue
*
uniqueSourceFileQueue
,
buildProperties
*
properties
.
Map
,
...
...
@@ -350,7 +354,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
l
.
logger
.
Info
(
tr
(
"Using cached library dependencies for file: %[1]s"
,
sourcePath
))
}
}
else
{
preprocFirstResult
,
preprocErr
=
preprocessor
.
GCC
(
sourcePath
,
targetFilePath
,
includeFolders
,
buildProperties
)
preprocFirstResult
,
preprocErr
=
preprocessor
.
GCC
(
ctx
,
sourcePath
,
targetFilePath
,
includeFolders
,
buildProperties
)
if
l
.
logger
.
Verbose
()
{
l
.
logger
.
WriteStdout
(
preprocFirstResult
.
Stdout
())
}
...
...
@@ -381,7 +385,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
// Library could not be resolved, show error
if
preprocErr
==
nil
||
preprocFirstResult
.
Stderr
()
==
nil
{
// Filename came from cache, so run preprocessor to obtain error to show
result
,
err
:=
preprocessor
.
GCC
(
sourcePath
,
targetFilePath
,
includeFolders
,
buildProperties
)
result
,
err
:=
preprocessor
.
GCC
(
ctx
,
sourcePath
,
targetFilePath
,
includeFolders
,
buildProperties
)
if
l
.
logger
.
Verbose
()
{
l
.
logger
.
WriteStdout
(
result
.
Stdout
())
}
...
...
internal/arduino/builder/internal/preprocessor/arduino_preprocessor.go
View file @
24ac0405
...
...
@@ -31,6 +31,7 @@ import (
// PreprocessSketchWithArduinoPreprocessor performs preprocessing of the arduino sketch
// using arduino-preprocessor (https://github.com/arduino/arduino-preprocessor).
func
PreprocessSketchWithArduinoPreprocessor
(
ctx
context
.
Context
,
sk
*
sketch
.
Sketch
,
buildPath
*
paths
.
Path
,
includeFolders
paths
.
PathList
,
lineOffset
int
,
buildProperties
*
properties
.
Map
,
onlyUpdateCompilationDatabase
bool
,
)
(
*
Result
,
error
)
{
...
...
@@ -42,7 +43,7 @@ func PreprocessSketchWithArduinoPreprocessor(
sourceFile
:=
buildPath
.
Join
(
"sketch"
,
sk
.
MainFile
.
Base
()
+
".cpp"
)
targetFile
:=
buildPath
.
Join
(
"preproc"
,
"sketch_merged.cpp"
)
gccResult
,
err
:=
GCC
(
sourceFile
,
targetFile
,
includeFolders
,
buildProperties
)
gccResult
,
err
:=
GCC
(
ctx
,
sourceFile
,
targetFile
,
includeFolders
,
buildProperties
)
verboseOut
.
Write
(
gccResult
.
Stdout
())
verboseOut
.
Write
(
gccResult
.
Stderr
())
if
err
!=
nil
{
...
...
@@ -78,7 +79,7 @@ func PreprocessSketchWithArduinoPreprocessor(
}
verboseOut
.
WriteString
(
commandLine
)
commandStdOut
,
commandStdErr
,
err
:=
command
.
RunAndCaptureOutput
(
c
ontext
.
Background
()
)
commandStdOut
,
commandStdErr
,
err
:=
command
.
RunAndCaptureOutput
(
c
tx
)
verboseOut
.
Write
(
commandStdErr
)
if
err
!=
nil
{
return
&
Result
{
args
:
gccResult
.
Args
(),
stdout
:
verboseOut
.
Bytes
(),
stderr
:
normalOut
.
Bytes
()},
err
...
...
internal/arduino/builder/internal/preprocessor/ctags.go
View file @
24ac0405
...
...
@@ -41,6 +41,7 @@ var DebugPreprocessor bool
// PreprocessSketchWithCtags performs preprocessing of the arduino sketch using CTags.
func
PreprocessSketchWithCtags
(
ctx
context
.
Context
,
sketch
*
sketch
.
Sketch
,
buildPath
*
paths
.
Path
,
includes
paths
.
PathList
,
lineOffset
int
,
buildProperties
*
properties
.
Map
,
onlyUpdateCompilationDatabase
,
verbose
bool
,
...
...
@@ -57,7 +58,7 @@ func PreprocessSketchWithCtags(
// Run GCC preprocessor
sourceFile
:=
buildPath
.
Join
(
"sketch"
,
sketch
.
MainFile
.
Base
()
+
".cpp"
)
result
,
err
:=
GCC
(
sourceFile
,
ctagsTarget
,
includes
,
buildProperties
)
result
,
err
:=
GCC
(
ctx
,
sourceFile
,
ctagsTarget
,
includes
,
buildProperties
)
stdout
.
Write
(
result
.
Stdout
())
stderr
.
Write
(
result
.
Stderr
())
if
err
!=
nil
{
...
...
@@ -84,7 +85,7 @@ func PreprocessSketchWithCtags(
}
// Run CTags on gcc-preprocessed source
ctagsOutput
,
ctagsStdErr
,
err
:=
RunCTags
(
ctagsTarget
,
buildProperties
)
ctagsOutput
,
ctagsStdErr
,
err
:=
RunCTags
(
ct
x
,
ct
agsTarget
,
buildProperties
)
if
verbose
{
stderr
.
Write
(
ctagsStdErr
)
}
...
...
@@ -179,7 +180,7 @@ func isFirstFunctionOutsideOfSource(firstFunctionLine int, sourceRows []string)
}
// RunCTags performs a run of ctags on the given source file. Returns the ctags output and the stderr contents.
func
RunCTags
(
sourceFile
*
paths
.
Path
,
buildProperties
*
properties
.
Map
)
([]
byte
,
[]
byte
,
error
)
{
func
RunCTags
(
ctx
context
.
Context
,
sourceFile
*
paths
.
Path
,
buildProperties
*
properties
.
Map
)
([]
byte
,
[]
byte
,
error
)
{
ctagsBuildProperties
:=
properties
.
NewMap
()
ctagsBuildProperties
.
Set
(
"tools.ctags.path"
,
"{runtime.tools.ctags.path}"
)
ctagsBuildProperties
.
Set
(
"tools.ctags.cmd.path"
,
"{path}/ctags"
)
...
...
@@ -202,7 +203,7 @@ func RunCTags(sourceFile *paths.Path, buildProperties *properties.Map) ([]byte,
if
err
!=
nil
{
return
nil
,
nil
,
err
}
stdout
,
stderr
,
err
:=
proc
.
RunAndCaptureOutput
(
c
ontext
.
Background
()
)
stdout
,
stderr
,
err
:=
proc
.
RunAndCaptureOutput
(
c
tx
)
// Append ctags arguments to stderr
args
:=
fmt
.
Sprintln
(
strings
.
Join
(
parts
,
" "
))
...
...
internal/arduino/builder/internal/preprocessor/gcc.go
View file @
24ac0405
...
...
@@ -30,6 +30,7 @@ import (
// GCC performs a run of the gcc preprocess (macro/includes expansion). The function outputs the result
// to targetFilePath. Returns the stdout/stderr of gcc if any.
func
GCC
(
ctx
context
.
Context
,
sourceFilePath
,
targetFilePath
*
paths
.
Path
,
includes
paths
.
PathList
,
buildProperties
*
properties
.
Map
,
)
(
Result
,
error
)
{
...
...
@@ -75,7 +76,7 @@ func GCC(
if
err
!=
nil
{
return
Result
{},
err
}
stdout
,
stderr
,
err
:=
proc
.
RunAndCaptureOutput
(
c
ontext
.
Background
()
)
stdout
,
stderr
,
err
:=
proc
.
RunAndCaptureOutput
(
c
tx
)
// Append gcc arguments to stdout
stdout
=
append
([]
byte
(
fmt
.
Sprintln
(
strings
.
Join
(
args
,
" "
))),
stdout
...
)
...
...
internal/arduino/builder/preprocess_sketch.go
View file @
24ac0405
...
...
@@ -24,6 +24,7 @@ import (
func
(
b
*
Builder
)
preprocessSketch
(
includes
paths
.
PathList
)
error
{
// In the future we might change the preprocessor
result
,
err
:=
preprocessor
.
PreprocessSketchWithCtags
(
b
.
ctx
,
b
.
sketch
,
b
.
buildPath
,
includes
,
b
.
lineOffset
,
b
.
buildProperties
,
b
.
onlyUpdateCompilationDatabase
,
b
.
logger
.
Verbose
(),
)
...
...
internal/arduino/cores/packagemanager/profiles.go
View file @
24ac0405
...
...
@@ -16,6 +16,7 @@
package
packagemanager
import
(
"context"
"fmt"
"net/url"
...
...
@@ -32,7 +33,7 @@ import (
// LoadHardwareForProfile load the hardware platforms for the given profile.
// If installMissing is true then possibly missing tools and platforms will be downloaded and installed.
func
(
pmb
*
Builder
)
LoadHardwareForProfile
(
p
*
sketch
.
Profile
,
installMissing
bool
,
downloadCB
rpc
.
DownloadProgressCB
,
taskCB
rpc
.
TaskProgressCB
,
settings
*
configuration
.
Settings
)
[]
error
{
func
(
pmb
*
Builder
)
LoadHardwareForProfile
(
ctx
context
.
Context
,
p
*
sketch
.
Profile
,
installMissing
bool
,
downloadCB
rpc
.
DownloadProgressCB
,
taskCB
rpc
.
TaskProgressCB
,
settings
*
configuration
.
Settings
)
[]
error
{
pmb
.
profile
=
p
// Load required platforms
...
...
@@ -40,7 +41,7 @@ func (pmb *Builder) LoadHardwareForProfile(p *sketch.Profile, installMissing boo
var
platformReleases
[]
*
cores
.
PlatformRelease
indexURLs
:=
map
[
string
]
*
url
.
URL
{}
for
_
,
platformRef
:=
range
p
.
Platforms
{
if
platformRelease
,
err
:=
pmb
.
loadProfilePlatform
(
platformRef
,
installMissing
,
downloadCB
,
taskCB
,
settings
);
err
!=
nil
{
if
platformRelease
,
err
:=
pmb
.
loadProfilePlatform
(
ctx
,
platformRef
,
installMissing
,
downloadCB
,
taskCB
,
settings
);
err
!=
nil
{
merr
=
append
(
merr
,
fmt
.
Errorf
(
"%s: %w"
,
tr
(
"loading required platform %s"
,
platformRef
),
err
))
logrus
.
WithField
(
"platform"
,
platformRef
)
.
WithError
(
err
)
.
Debugf
(
"Error loading platform for profile"
)
}
else
{
...
...
@@ -68,7 +69,7 @@ func (pmb *Builder) LoadHardwareForProfile(p *sketch.Profile, installMissing boo
return
merr
}
func
(
pmb
*
Builder
)
loadProfilePlatform
(
platformRef
*
sketch
.
ProfilePlatformReference
,
installMissing
bool
,
downloadCB
rpc
.
DownloadProgressCB
,
taskCB
rpc
.
TaskProgressCB
,
settings
*
configuration
.
Settings
)
(
*
cores
.
PlatformRelease
,
error
)
{
func
(
pmb
*
Builder
)
loadProfilePlatform
(
ctx
context
.
Context
,
platformRef
*
sketch
.
ProfilePlatformReference
,
installMissing
bool
,
downloadCB
rpc
.
DownloadProgressCB
,
taskCB
rpc
.
TaskProgressCB
,
settings
*
configuration
.
Settings
)
(
*
cores
.
PlatformRelease
,
error
)
{
targetPackage
:=
pmb
.
packages
.
GetOrCreatePackage
(
platformRef
.
Packager
)
platform
:=
targetPackage
.
GetOrCreatePlatform
(
platformRef
.
Architecture
)
release
:=
platform
.
GetOrCreateRelease
(
platformRef
.
Version
)
...
...
@@ -77,14 +78,14 @@ func (pmb *Builder) loadProfilePlatform(platformRef *sketch.ProfilePlatformRefer
destDir
:=
settings
.
ProfilesCacheDir
()
.
Join
(
uid
)
if
!
destDir
.
IsDir
()
&&
installMissing
{
// Try installing the missing platform
if
err
:=
pmb
.
installMissingProfilePlatform
(
platformRef
,
destDir
,
downloadCB
,
taskCB
);
err
!=
nil
{
if
err
:=
pmb
.
installMissingProfilePlatform
(
ctx
,
platformRef
,
destDir
,
downloadCB
,
taskCB
);
err
!=
nil
{
return
nil
,
err
}
}
return
release
,
pmb
.
loadPlatformRelease
(
release
,
destDir
)
}
func
(
pmb
*
Builder
)
installMissingProfilePlatform
(
platformRef
*
sketch
.
ProfilePlatformReference
,
destDir
*
paths
.
Path
,
downloadCB
rpc
.
DownloadProgressCB
,
taskCB
rpc
.
TaskProgressCB
)
error
{
func
(
pmb
*
Builder
)
installMissingProfilePlatform
(
ctx
context
.
Context
,
platformRef
*
sketch
.
ProfilePlatformReference
,
destDir
*
paths
.
Path
,
downloadCB
rpc
.
DownloadProgressCB
,
taskCB
rpc
.
TaskProgressCB
)
error
{
// Instantiate a temporary package manager only for platform installation
_
=
pmb
.
tempDir
.
MkdirAll
()
tmp
,
err
:=
paths
.
MkTempDir
(
pmb
.
tempDir
.
String
(),
""
)
...
...
@@ -103,7 +104,7 @@ func (pmb *Builder) installMissingProfilePlatform(platformRef *sketch.ProfilePla
}
for
_
,
indexURL
:=
range
indexesToDownload
{
indexResource
:=
resources
.
IndexResource
{
URL
:
indexURL
}
if
err
:=
indexResource
.
Download
(
tmpPmb
.
IndexDir
,
downloadCB
,
pmb
.
downloaderConfig
);
err
!=
nil
{
if
err
:=
indexResource
.
Download
(
ctx
,
tmpPmb
.
IndexDir
,
downloadCB
,
pmb
.
downloaderConfig
);
err
!=
nil
{
taskCB
(
&
rpc
.
TaskProgress
{
Name
:
tr
(
"Error downloading %s"
,
indexURL
)})
return
&
cmderrors
.
FailedDownloadError
{
Message
:
tr
(
"Error downloading %s"
,
indexURL
),
Cause
:
err
}
}
...
...
internal/arduino/resources/index.go
View file @
24ac0405
...
...
@@ -58,7 +58,7 @@ func (res *IndexResource) IndexFileName() (string, error) {
// Download will download the index and possibly check the signature using the Arduino's public key.
// If the file is in .gz format it will be unpacked first.
func
(
res
*
IndexResource
)
Download
(
destDir
*
paths
.
Path
,
downloadCB
rpc
.
DownloadProgressCB
,
config
downloader
.
Config
)
error
{
func
(
res
*
IndexResource
)
Download
(
ctx
context
.
Context
,
destDir
*
paths
.
Path
,
downloadCB
rpc
.
DownloadProgressCB
,
config
downloader
.
Config
)
error
{
// Create destination directory
if
err
:=
destDir
.
MkdirAll
();
err
!=
nil
{
return
&
cmderrors
.
PermissionDeniedError
{
Message
:
tr
(
"Can't create data directory %s"
,
destDir
),
Cause
:
err
}
...
...
@@ -100,7 +100,7 @@ func (res *IndexResource) Download(destDir *paths.Path, downloadCB rpc.DownloadP
defer
f
.
Close
()
tmpArchivePath
:=
tmp
.
Join
(
"archive"
)
_
=
tmpArchivePath
.
MkdirAll
()
if
err
:=
extract
.
Bz2
(
c
ontext
.
Background
()
,
f
,
tmpArchivePath
.
String
(),
nil
);
err
!=
nil
{
if
err
:=
extract
.
Bz2
(
c
tx
,
f
,
tmpArchivePath
.
String
(),
nil
);
err
!=
nil
{
return
&
cmderrors
.
PermissionDeniedError
{
Message
:
tr
(
"Error extracting %s"
,
tmpIndexPath
),
Cause
:
err
}
}
...
...
internal/arduino/resources/resources_test.go
View file @
24ac0405
...
...
@@ -16,6 +16,7 @@
package
resources
import
(
"context"
"crypto"
"encoding/hex"
"fmt"
...
...
@@ -116,6 +117,7 @@ func TestDownloadAndChecksums(t *testing.T) {
}
func
TestIndexDownloadAndSignatureWithinArchive
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
// Spawn test webserver
mux
:=
http
.
NewServeMux
()
fs
:=
http
.
FileServer
(
http
.
Dir
(
"testdata"
))
...
...
@@ -132,7 +134,7 @@ func TestIndexDownloadAndSignatureWithinArchive(t *testing.T) {
destDir
,
err
:=
paths
.
MkTempDir
(
""
,
""
)
require
.
NoError
(
t
,
err
)
defer
destDir
.
RemoveAll
()
err
=
idxResource
.
Download
(
destDir
,
func
(
curr
*
rpc
.
DownloadProgress
)
{},
downloader
.
GetDefaultConfig
())
err
=
idxResource
.
Download
(
ctx
,
destDir
,
func
(
curr
*
rpc
.
DownloadProgress
)
{},
downloader
.
GetDefaultConfig
())
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
destDir
.
Join
(
"package_index.json"
)
.
Exist
())
require
.
True
(
t
,
destDir
.
Join
(
"package_index.json.sig"
)
.
Exist
())
...
...
@@ -143,7 +145,7 @@ func TestIndexDownloadAndSignatureWithinArchive(t *testing.T) {
invDestDir
,
err
:=
paths
.
MkTempDir
(
""
,
""
)
require
.
NoError
(
t
,
err
)
defer
invDestDir
.
RemoveAll
()
err
=
invIdxResource
.
Download
(
invDestDir
,
func
(
curr
*
rpc
.
DownloadProgress
)
{},
downloader
.
GetDefaultConfig
())
err
=
invIdxResource
.
Download
(
ctx
,
invDestDir
,
func
(
curr
*
rpc
.
DownloadProgress
)
{},
downloader
.
GetDefaultConfig
())
require
.
Error
(
t
,
err
)
require
.
Contains
(
t
,
err
.
Error
(),
"invalid signature"
)
require
.
False
(
t
,
invDestDir
.
Join
(
"package_index.json"
)
.
Exist
())
...
...
internal/cli/arguments/completion.go
View file @
24ac0405
...
...
@@ -29,7 +29,7 @@ import (
func
GetInstalledBoards
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
)
[]
string
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
list
,
_
:=
srv
.
BoardListAll
(
c
ontext
.
Background
()
,
&
rpc
.
BoardListAllRequest
{
list
,
_
:=
srv
.
BoardListAll
(
c
tx
,
&
rpc
.
BoardListAllRequest
{
Instance
:
inst
,
SearchArgs
:
nil
,
IncludeHiddenBoards
:
false
,
...
...
@@ -53,7 +53,7 @@ func GetInstalledProgrammers(ctx context.Context, srv rpc.ArduinoCoreServiceServ
SearchArgs
:
nil
,
IncludeHiddenBoards
:
false
,
}
list
,
_
:=
srv
.
BoardListAll
(
c
ontext
.
Background
()
,
listAllReq
)
list
,
_
:=
srv
.
BoardListAll
(
c
tx
,
listAllReq
)
installedProgrammers
:=
make
(
map
[
string
]
string
)
for
_
,
board
:=
range
list
.
GetBoards
()
{
...
...
@@ -149,7 +149,7 @@ func getLibraries(ctx context.Context, srv rpc.ArduinoCoreServiceServer, all boo
func
GetInstallableLibs
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
)
[]
string
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
libs
,
_
:=
srv
.
LibrarySearch
(
c
ontext
.
Background
()
,
&
rpc
.
LibrarySearchRequest
{
libs
,
_
:=
srv
.
LibrarySearch
(
c
tx
,
&
rpc
.
LibrarySearchRequest
{
Instance
:
inst
,
SearchArgs
:
""
,
// if no query is specified all the libs are returned
})
...
...
internal/cli/arguments/fqbn.go
View file @
24ac0405
...
...
@@ -37,7 +37,7 @@ type Fqbn struct {
func
(
f
*
Fqbn
)
AddToCommand
(
cmd
*
cobra
.
Command
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
cmd
.
Flags
()
.
StringVarP
(
&
f
.
fqbn
,
"fqbn"
,
"b"
,
""
,
tr
(
"Fully Qualified Board Name, e.g.: arduino:avr:uno"
))
cmd
.
RegisterFlagCompletionFunc
(
"fqbn"
,
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
GetInstalledBoards
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
GetInstalledBoards
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
})
cmd
.
Flags
()
.
StringSliceVar
(
&
f
.
boardOptions
,
"board-options"
,
[]
string
{},
tr
(
"List of board options separated by commas. Or can be used multiple times for multiple options."
))
...
...
@@ -70,7 +70,7 @@ func (f *Fqbn) Set(fqbn string) {
// - the port is not found, in this case nil is returned
// - the FQBN autodetection fail, in this case the function prints an error and
// terminates the execution
func
CalculateFQBNAndPort
(
portArgs
*
Port
,
fqbnArg
*
Fqbn
,
instance
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
,
defaultFQBN
,
defaultAddress
,
defaultProtocol
string
)
(
string
,
*
rpc
.
Port
)
{
func
CalculateFQBNAndPort
(
ctx
context
.
Context
,
portArgs
*
Port
,
fqbnArg
*
Fqbn
,
instance
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
,
defaultFQBN
,
defaultAddress
,
defaultProtocol
string
)
(
string
,
*
rpc
.
Port
)
{
fqbn
:=
fqbnArg
.
String
()
if
fqbn
==
""
{
fqbn
=
defaultFQBN
...
...
@@ -79,14 +79,14 @@ func CalculateFQBNAndPort(portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance,
if
portArgs
==
nil
||
portArgs
.
address
==
""
{
feedback
.
FatalError
(
&
cmderrors
.
MissingFQBNError
{},
feedback
.
ErrGeneric
)
}
fqbn
,
port
:=
portArgs
.
DetectFQBN
(
instance
,
srv
)
fqbn
,
port
:=
portArgs
.
DetectFQBN
(
ctx
,
instance
,
srv
)
if
fqbn
==
""
{
feedback
.
FatalError
(
&
cmderrors
.
MissingFQBNError
{},
feedback
.
ErrGeneric
)
}
return
fqbn
,
port
}
port
,
err
:=
portArgs
.
GetPort
(
instance
,
srv
,
defaultAddress
,
defaultProtocol
)
port
,
err
:=
portArgs
.
GetPort
(
ctx
,
instance
,
srv
,
defaultAddress
,
defaultProtocol
)
if
err
!=
nil
{
feedback
.
Fatal
(
tr
(
"Error getting port metadata: %v"
,
err
),
feedback
.
ErrGeneric
)
}
...
...
internal/cli/arguments/port.go
View file @
24ac0405
...
...
@@ -42,11 +42,11 @@ type Port struct {
func
(
p
*
Port
)
AddToCommand
(
cmd
*
cobra
.
Command
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
cmd
.
Flags
()
.
StringVarP
(
&
p
.
address
,
"port"
,
"p"
,
""
,
tr
(
"Upload port address, e.g.: COM3 or /dev/ttyACM2"
))
cmd
.
RegisterFlagCompletionFunc
(
"port"
,
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
f
.
Map
(
GetAvailablePorts
(
c
ontext
.
Background
(),
srv
),
(
*
rpc
.
Port
)
.
GetAddress
),
cobra
.
ShellCompDirectiveDefault
return
f
.
Map
(
GetAvailablePorts
(
c
md
.
Context
(),
srv
),
(
*
rpc
.
Port
)
.
GetAddress
),
cobra
.
ShellCompDirectiveDefault
})
cmd
.
Flags
()
.
StringVarP
(
&
p
.
protocol
,
"protocol"
,
"l"
,
""
,
tr
(
"Upload port protocol, e.g: serial"
))
cmd
.
RegisterFlagCompletionFunc
(
"protocol"
,
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
f
.
Map
(
GetAvailablePorts
(
c
ontext
.
Background
(),
srv
),
(
*
rpc
.
Port
)
.
GetProtocol
),
cobra
.
ShellCompDirectiveDefault
return
f
.
Map
(
GetAvailablePorts
(
c
md
.
Context
(),
srv
),
(
*
rpc
.
Port
)
.
GetProtocol
),
cobra
.
ShellCompDirectiveDefault
})
p
.
timeout
.
AddToCommand
(
cmd
)
}
...
...
@@ -56,12 +56,12 @@ func (p *Port) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceServer
// This method allows will bypass the discoveries if:
// - a nil instance is passed: in this case the plain port and protocol arguments are returned (even if empty)
// - a protocol is specified: in this case the discoveries are not needed to autodetect the protocol.
func
(
p
*
Port
)
GetPortAddressAndProtocol
(
instance
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
,
defaultAddress
,
defaultProtocol
string
)
(
string
,
string
,
error
)
{
func
(
p
*
Port
)
GetPortAddressAndProtocol
(
ctx
context
.
Context
,
instance
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
,
defaultAddress
,
defaultProtocol
string
)
(
string
,
string
,
error
)
{
if
p
.
protocol
!=
""
||
instance
==
nil
{
return
p
.
address
,
p
.
protocol
,
nil
}
port
,
err
:=
p
.
GetPort
(
instance
,
srv
,
defaultAddress
,
defaultProtocol
)
port
,
err
:=
p
.
GetPort
(
ctx
,
instance
,
srv
,
defaultAddress
,
defaultProtocol
)
if
err
!=
nil
{
return
""
,
""
,
err
}
...
...
@@ -70,7 +70,7 @@ func (p *Port) GetPortAddressAndProtocol(instance *rpc.Instance, srv rpc.Arduino
// GetPort returns the Port obtained by parsing command line arguments.
// The extra metadata for the ports is obtained using the pluggable discoveries.
func
(
p
*
Port
)
GetPort
(
instance
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
,
defaultAddress
,
defaultProtocol
string
)
(
*
rpc
.
Port
,
error
)
{
func
(
p
*
Port
)
GetPort
(
ctx
context
.
Context
,
instance
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
,
defaultAddress
,
defaultProtocol
string
)
(
*
rpc
.
Port
,
error
)
{
address
:=
p
.
address
protocol
:=
p
.
protocol
if
address
==
""
&&
(
defaultAddress
!=
""
||
defaultProtocol
!=
""
)
{
...
...
@@ -88,7 +88,7 @@ func (p *Port) GetPort(instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer,
}
logrus
.
WithField
(
"port"
,
address
)
.
Tracef
(
"Upload port"
)
ctx
,
cancel
:=
context
.
WithCancel
(
c
ontext
.
Background
()
)
ctx
,
cancel
:=
context
.
WithCancel
(
c
tx
)
defer
cancel
()
stream
,
watcher
:=
commands
.
BoardListWatchProxyToChan
(
ctx
)
...
...
@@ -131,8 +131,8 @@ func (p *Port) GetSearchTimeout() time.Duration {
// DetectFQBN tries to identify the board connected to the port and returns the
// discovered Port object together with the FQBN. If the port does not match
// exactly 1 board,
func
(
p
*
Port
)
DetectFQBN
(
inst
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
)
(
string
,
*
rpc
.
Port
)
{
detectedPorts
,
err
:=
srv
.
BoardList
(
c
ontext
.
Background
()
,
&
rpc
.
BoardListRequest
{
func
(
p
*
Port
)
DetectFQBN
(
ctx
context
.
Context
,
inst
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
)
(
string
,
*
rpc
.
Port
)
{
detectedPorts
,
err
:=
srv
.
BoardList
(
c
tx
,
&
rpc
.
BoardListRequest
{
Instance
:
inst
,
Timeout
:
p
.
timeout
.
Get
()
.
Milliseconds
(),
})
...
...
internal/cli/arguments/profiles.go
View file @
24ac0405
...
...
@@ -16,8 +16,6 @@
package
arguments
import
(
"context"
rpc
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/spf13/cobra"
)
...
...
@@ -37,7 +35,7 @@ func (f *Profile) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceSer
if
len
(
args
)
>
0
{
sketchProfile
=
args
[
0
]
}
return
GetSketchProfiles
(
c
ontext
.
Background
(),
srv
,
sketchProfile
),
cobra
.
ShellCompDirectiveDefault
return
GetSketchProfiles
(
c
md
.
Context
(),
srv
,
sketchProfile
),
cobra
.
ShellCompDirectiveDefault
})
}
...
...
internal/cli/arguments/programmer.go
View file @
24ac0405
...
...
@@ -33,20 +33,20 @@ type Programmer struct {
func
(
p
*
Programmer
)
AddToCommand
(
cmd
*
cobra
.
Command
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
cmd
.
Flags
()
.
StringVarP
(
&
p
.
programmer
,
"programmer"
,
"P"
,
""
,
tr
(
"Programmer to use, e.g: atmel_ice"
))
cmd
.
RegisterFlagCompletionFunc
(
"programmer"
,
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
GetInstalledProgrammers
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
GetInstalledProgrammers
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
})
}
// String returns the programmer specified by the user, or the default programmer
// for the given board if defined.
func
(
p
*
Programmer
)
String
(
inst
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
,
fqbn
string
)
string
{
func
(
p
*
Programmer
)
String
(
ctx
context
.
Context
,
inst
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
,
fqbn
string
)
string
{
if
p
.
programmer
!=
""
{
return
p
.
programmer
}
if
inst
==
nil
||
fqbn
==
""
{
return
""
}
details
,
err
:=
srv
.
BoardDetails
(
c
ontext
.
Background
()
,
&
rpc
.
BoardDetailsRequest
{
details
,
err
:=
srv
.
BoardDetails
(
c
tx
,
&
rpc
.
BoardDetailsRequest
{
Instance
:
inst
,
Fqbn
:
fqbn
,
})
...
...
internal/cli/board/attach.go
View file @
24ac0405
...
...
@@ -40,11 +40,12 @@ func initAttachCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" "
+
os
.
Args
[
0
]
+
" board attach -P atmel_ice"
,
Args
:
cobra
.
MaximumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
ctx
:=
cmd
.
Context
()
sketchPath
:=
""
if
len
(
args
)
>
0
{
sketchPath
=
args
[
0
]
}
runAttachCommand
(
srv
,
sketchPath
,
&
port
,
fqbn
.
String
(),
&
programmer
)
runAttachCommand
(
ctx
,
srv
,
sketchPath
,
&
port
,
fqbn
.
String
(),
&
programmer
)
},
}
fqbn
.
AddToCommand
(
attachCommand
,
srv
)
...
...
@@ -54,11 +55,10 @@ func initAttachCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
attachCommand
}
func
runAttachCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
path
string
,
port
*
arguments
.
Port
,
fqbn
string
,
programmer
*
arguments
.
Programmer
)
{
ctx
:=
context
.
Background
()
func
runAttachCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
path
string
,
port
*
arguments
.
Port
,
fqbn
string
,
programmer
*
arguments
.
Programmer
)
{
sketchPath
:=
arguments
.
InitSketchPath
(
path
)
portAddress
,
portProtocol
,
_
:=
port
.
GetPortAddressAndProtocol
(
nil
,
srv
,
""
,
""
)
portAddress
,
portProtocol
,
_
:=
port
.
GetPortAddressAndProtocol
(
ctx
,
nil
,
srv
,
""
,
""
)
newDefaults
,
err
:=
srv
.
SetSketchDefaults
(
ctx
,
&
rpc
.
SetSketchDefaultsRequest
{
SketchPath
:
sketchPath
.
String
(),
DefaultFqbn
:
fqbn
,
...
...
internal/cli/board/details.go
View file @
24ac0405
...
...
@@ -43,7 +43,7 @@ func initDetailsCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" board details -b arduino:avr:nano"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runDetailsCommand
(
srv
,
fqbn
.
String
(),
showFullDetails
,
listProgrammers
,
showProperties
)
runDetailsCommand
(
cmd
.
Context
(),
srv
,
fqbn
.
String
(),
showFullDetails
,
listProgrammers
,
showProperties
)
},
}
...
...
@@ -55,8 +55,7 @@ func initDetailsCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
detailsCommand
}
func
runDetailsCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
fqbn
string
,
showFullDetails
,
listProgrammers
bool
,
showProperties
arguments
.
ShowProperties
)
{
ctx
:=
context
.
Background
()
func
runDetailsCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
fqbn
string
,
showFullDetails
,
listProgrammers
bool
,
showProperties
arguments
.
ShowProperties
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli board details`"
)
...
...
@@ -65,7 +64,7 @@ func runDetailsCommand(srv rpc.ArduinoCoreServiceServer, fqbn string, showFullDe
if
err
!=
nil
{
feedback
.
Fatal
(
err
.
Error
(),
feedback
.
ErrBadArgument
)
}
res
,
err
:=
srv
.
BoardDetails
(
c
ontext
.
Background
()
,
&
rpc
.
BoardDetailsRequest
{
res
,
err
:=
srv
.
BoardDetails
(
c
tx
,
&
rpc
.
BoardDetailsRequest
{
Instance
:
inst
,
Fqbn
:
fqbn
,
DoNotExpandBuildProperties
:
showPropertiesMode
==
arguments
.
ShowPropertiesUnexpanded
,
...
...
internal/cli/board/list.go
View file @
24ac0405
...
...
@@ -46,7 +46,7 @@ func initListCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" board list --discovery-timeout 10s"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runListCommand
(
srv
,
watch
,
timeoutArg
.
Get
()
.
Milliseconds
(),
fqbn
.
String
())
runListCommand
(
cmd
.
Context
(),
srv
,
watch
,
timeoutArg
.
Get
()
.
Milliseconds
(),
fqbn
.
String
())
},
}
...
...
@@ -57,18 +57,17 @@ func initListCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
}
// runListCommand detects and lists the connected arduino boards
func
runListCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
watch
bool
,
timeout
int64
,
fqbn
string
)
{
ctx
:=
context
.
Background
()
func
runListCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
watch
bool
,
timeout
int64
,
fqbn
string
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli board list`"
)
if
watch
{
watchList
(
inst
,
srv
)
watchList
(
ctx
,
inst
,
srv
)
return
}
list
,
err
:=
srv
.
BoardList
(
c
ontext
.
Background
()
,
&
rpc
.
BoardListRequest
{
list
,
err
:=
srv
.
BoardList
(
c
tx
,
&
rpc
.
BoardListRequest
{
Instance
:
inst
,
Timeout
:
timeout
,
Fqbn
:
fqbn
,
...
...
@@ -89,8 +88,8 @@ func runListCommand(srv rpc.ArduinoCoreServiceServer, watch bool, timeout int64,
feedback
.
PrintResult
(
listResult
{
result
.
NewDetectedPorts
(
ports
)})
}
func
watchList
(
inst
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
stream
,
eventsChan
:=
commands
.
BoardListWatchProxyToChan
(
c
ontext
.
Background
()
)
func
watchList
(
ctx
context
.
Context
,
inst
*
rpc
.
Instance
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
stream
,
eventsChan
:=
commands
.
BoardListWatchProxyToChan
(
c
tx
)
err
:=
srv
.
BoardListWatch
(
&
rpc
.
BoardListWatchRequest
{
Instance
:
inst
},
stream
)
if
err
!=
nil
{
feedback
.
Fatal
(
tr
(
"Error detecting boards: %v"
,
err
),
feedback
.
ErrNetwork
)
...
...
internal/cli/board/listall.go
View file @
24ac0405
...
...
@@ -43,7 +43,7 @@ for a specific board if you specify the board name`),
" "
+
os
.
Args
[
0
]
+
" board listall zero"
,
Args
:
cobra
.
ArbitraryArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runListAllCommand
(
args
,
srv
)
runListAllCommand
(
cmd
.
Context
(),
args
,
srv
)
},
}
listAllCommand
.
Flags
()
.
BoolVarP
(
&
showHiddenBoard
,
"show-hidden"
,
"a"
,
false
,
tr
(
"Show also boards marked as 'hidden' in the platform"
))
...
...
@@ -51,13 +51,12 @@ for a specific board if you specify the board name`),
}
// runListAllCommand list all installed boards
func
runListAllCommand
(
args
[]
string
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
ctx
:=
context
.
Background
()
func
runListAllCommand
(
ctx
context
.
Context
,
args
[]
string
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli board listall`"
)
list
,
err
:=
srv
.
BoardListAll
(
c
ontext
.
Background
()
,
&
rpc
.
BoardListAllRequest
{
list
,
err
:=
srv
.
BoardListAll
(
c
tx
,
&
rpc
.
BoardListAllRequest
{
Instance
:
inst
,
SearchArgs
:
args
,
IncludeHiddenBoards
:
showHiddenBoard
,
...
...
internal/cli/board/search.go
View file @
24ac0405
...
...
@@ -41,20 +41,19 @@ func initSearchCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" "
+
os
.
Args
[
0
]
+
" board search zero"
,
Args
:
cobra
.
ArbitraryArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runSearchCommand
(
srv
,
args
)
runSearchCommand
(
cmd
.
Context
(),
srv
,
args
)
},
}
searchCommand
.
Flags
()
.
BoolVarP
(
&
showHiddenBoard
,
"show-hidden"
,
"a"
,
false
,
tr
(
"Show also boards marked as 'hidden' in the platform"
))
return
searchCommand
}
func
runSearchCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
ctx
:=
context
.
Background
()
func
runSearchCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli board search`"
)
res
,
err
:=
srv
.
BoardSearch
(
c
ontext
.
Background
()
,
&
rpc
.
BoardSearchRequest
{
res
,
err
:=
srv
.
BoardSearch
(
c
tx
,
&
rpc
.
BoardSearchRequest
{
Instance
:
inst
,
SearchArgs
:
strings
.
Join
(
args
,
" "
),
IncludeHiddenBoards
:
showHiddenBoard
,
...
...
internal/cli/burnbootloader/burnbootloader.go
View file @
24ac0405
...
...
@@ -50,7 +50,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" burn-bootloader -b arduino:avr:uno -P atmel_ice"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runBootloaderCommand
(
srv
)
runBootloaderCommand
(
cmd
.
Context
(),
srv
)
},
}
...
...
@@ -65,14 +65,13 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
burnBootloaderCommand
}
func
runBootloaderCommand
(
srv
rpc
.
ArduinoCoreServiceServer
)
{
ctx
:=
context
.
Background
()
func
runBootloaderCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
instance
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli burn-bootloader`"
)
// We don't need a Sketch to upload a board's bootloader
discoveryPort
,
err
:=
port
.
GetPort
(
instance
,
srv
,
""
,
""
)
discoveryPort
,
err
:=
port
.
GetPort
(
ctx
,
instance
,
srv
,
""
,
""
)
if
err
!=
nil
{
feedback
.
Fatal
(
tr
(
"Error during Upload: %v"
,
err
),
feedback
.
ErrGeneric
)
}
...
...
@@ -85,7 +84,7 @@ func runBootloaderCommand(srv rpc.ArduinoCoreServiceServer) {
Port
:
discoveryPort
,
Verbose
:
verbose
,
Verify
:
verify
,
Programmer
:
programmer
.
String
(
instance
,
srv
,
fqbn
.
String
()),
Programmer
:
programmer
.
String
(
ctx
,
instance
,
srv
,
fqbn
.
String
()),
DryRun
:
dryRun
,
},
stream
);
err
!=
nil
{
errcode
:=
feedback
.
ErrGeneric
...
...
internal/cli/cache/clean.go
View file @
24ac0405
...
...
@@ -33,16 +33,16 @@ func initCleanCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" cache clean"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runCleanCommand
(
srv
)
runCleanCommand
(
cmd
.
Context
(),
srv
)
},
}
return
cleanCommand
}
func
runCleanCommand
(
srv
rpc
.
ArduinoCoreServiceServer
)
{
func
runCleanCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
logrus
.
Info
(
"Executing `arduino-cli cache clean`"
)
_
,
err
:=
srv
.
CleanDownloadCacheDirectory
(
c
ontext
.
Background
()
,
&
rpc
.
CleanDownloadCacheDirectoryRequest
{})
_
,
err
:=
srv
.
CleanDownloadCacheDirectory
(
c
tx
,
&
rpc
.
CleanDownloadCacheDirectoryRequest
{})
if
err
!=
nil
{
feedback
.
Fatal
(
tr
(
"Error cleaning caches: %v"
,
err
),
feedback
.
ErrGeneric
)
}
...
...
internal/cli/cli.go
View file @
24ac0405
...
...
@@ -115,7 +115,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
if
cmd
.
Name
()
!=
"version"
{
updaterMessageChan
=
make
(
chan
*
semver
.
Version
)
go
func
()
{
res
,
err
:=
srv
.
CheckForArduinoCLIUpdates
(
c
ontext
.
Background
()
,
&
rpc
.
CheckForArduinoCLIUpdatesRequest
{})
res
,
err
:=
srv
.
CheckForArduinoCLIUpdates
(
c
tx
,
&
rpc
.
CheckForArduinoCLIUpdatesRequest
{})
if
err
!=
nil
{
logrus
.
Warnf
(
"Error checking for updates: %v"
,
err
)
updaterMessageChan
<-
nil
...
...
internal/cli/compile/compile.go
View file @
24ac0405
...
...
@@ -16,7 +16,6 @@
package
compile
import
(
"context"
"encoding/json"
"errors"
"fmt"
...
...
@@ -141,7 +140,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configuration) *
func
runCompileCommand
(
cmd
*
cobra
.
Command
,
args
[]
string
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
logrus
.
Info
(
"Executing `arduino-cli compile`"
)
ctx
:=
c
ontext
.
Background
()
ctx
:=
c
md
.
Context
()
if
profileArg
.
Get
()
!=
""
{
if
len
(
libraries
)
>
0
{
...
...
@@ -178,7 +177,7 @@ func runCompileCommand(cmd *cobra.Command, args []string, srv rpc.ArduinoCoreSer
fqbnArg
.
Set
(
profile
.
GetFqbn
())
}
fqbn
,
port
:=
arguments
.
CalculateFQBNAndPort
(
&
portArgs
,
&
fqbnArg
,
inst
,
srv
,
sk
.
GetDefaultFqbn
(),
sk
.
GetDefaultPort
(),
sk
.
GetDefaultProtocol
())
fqbn
,
port
:=
arguments
.
CalculateFQBNAndPort
(
ctx
,
&
portArgs
,
&
fqbnArg
,
inst
,
srv
,
sk
.
GetDefaultFqbn
(),
sk
.
GetDefaultPort
(),
sk
.
GetDefaultProtocol
())
if
keysKeychain
!=
""
||
signKey
!=
""
||
encryptKey
!=
""
{
arguments
.
CheckFlagsMandatory
(
cmd
,
"keys-keychain"
,
"sign-key"
,
"encrypt-key"
)
...
...
@@ -274,7 +273,7 @@ func runCompileCommand(cmd *cobra.Command, args []string, srv rpc.ArduinoCoreSer
prog
:=
profile
.
GetProgrammer
()
if
prog
==
""
||
programmer
.
GetProgrammer
()
!=
""
{
prog
=
programmer
.
String
(
inst
,
srv
,
fqbn
)
prog
=
programmer
.
String
(
ctx
,
inst
,
srv
,
fqbn
)
}
if
prog
==
""
{
prog
=
sk
.
GetDefaultProgrammer
()
...
...
internal/cli/config/get.go
View file @
24ac0405
...
...
@@ -39,7 +39,7 @@ func initGetCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" "
+
os
.
Args
[
0
]
+
" config get board_manager.additional_urls"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runGetCommand
(
srv
,
args
)
runGetCommand
(
cmd
.
Context
(),
srv
,
args
)
},
ValidArgsFunction
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
ctx
:=
cmd
.
Context
()
...
...
@@ -49,9 +49,8 @@ func initGetCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
getCommand
}
func
runGetCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
func
runGetCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino-cli config get`"
)
ctx
:=
context
.
Background
()
for
_
,
toGet
:=
range
args
{
resp
,
err
:=
srv
.
SettingsGetValue
(
ctx
,
&
rpc
.
SettingsGetValueRequest
{
Key
:
toGet
})
...
...
internal/cli/core/download.go
View file @
24ac0405
...
...
@@ -39,17 +39,16 @@ func initDownloadCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" "
+
os
.
Args
[
0
]
+
" core download arduino:samd@1.6.9 # "
+
tr
(
"download a specific version (in this case 1.6.9)."
),
Args
:
cobra
.
MinimumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runDownloadCommand
(
srv
,
args
)
runDownloadCommand
(
cmd
.
Context
(),
srv
,
args
)
},
ValidArgsFunction
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstallableCores
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
arguments
.
GetInstallableCores
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
},
}
return
downloadCommand
}
func
runDownloadCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
ctx
:=
context
.
Background
()
func
runDownloadCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli core download`"
)
...
...
internal/cli/core/install.go
View file @
24ac0405
...
...
@@ -45,10 +45,10 @@ func initInstallCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
arguments
.
CheckFlagsConflicts
(
cmd
,
"run-post-install"
,
"skip-post-install"
)
},
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runInstallCommand
(
srv
,
args
,
scriptFlags
,
noOverwrite
)
runInstallCommand
(
cmd
.
Context
(),
srv
,
args
,
scriptFlags
,
noOverwrite
)
},
ValidArgsFunction
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstallableCores
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
arguments
.
GetInstallableCores
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
},
}
scriptFlags
.
AddToCommand
(
installCommand
)
...
...
@@ -56,9 +56,8 @@ func initInstallCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
installCommand
}
func
runInstallCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
scriptFlags
arguments
.
PrePostScriptsFlags
,
noOverwrite
bool
)
{
func
runInstallCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
scriptFlags
arguments
.
PrePostScriptsFlags
,
noOverwrite
bool
)
{
logrus
.
Info
(
"Executing `arduino-cli core install`"
)
ctx
:=
context
.
Background
()
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
platformsRefs
,
err
:=
arguments
.
ParseReferences
(
ctx
,
srv
,
args
)
...
...
internal/cli/core/list.go
View file @
24ac0405
...
...
@@ -38,7 +38,7 @@ func initListCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" core list"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runListCommand
(
srv
,
all
,
updatableOnly
)
runListCommand
(
cmd
.
Context
(),
srv
,
all
,
updatableOnly
)
},
}
listCommand
.
Flags
()
.
BoolVar
(
&
updatableOnly
,
"updatable"
,
false
,
tr
(
"List updatable platforms."
))
...
...
@@ -46,8 +46,7 @@ func initListCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
listCommand
}
func
runListCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
all
bool
,
updatableOnly
bool
)
{
ctx
:=
context
.
Background
()
func
runListCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
all
bool
,
updatableOnly
bool
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli core list`"
)
List
(
ctx
,
srv
,
inst
,
all
,
updatableOnly
)
...
...
internal/cli/core/search.go
View file @
24ac0405
...
...
@@ -41,7 +41,7 @@ func initSearchCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" core search MKRZero -a -v"
,
Args
:
cobra
.
ArbitraryArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runSearchCommand
(
srv
,
args
,
allVersions
)
runSearchCommand
(
cmd
.
Context
(),
srv
,
args
,
allVersions
)
},
}
searchCommand
.
Flags
()
.
BoolVarP
(
&
allVersions
,
"all"
,
"a"
,
false
,
tr
(
"Show all available core versions."
))
...
...
@@ -52,8 +52,7 @@ func initSearchCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
// indexUpdateInterval specifies the time threshold over which indexes are updated
const
indexUpdateInterval
=
24
*
time
.
Hour
func
runSearchCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
allVersions
bool
)
{
ctx
:=
context
.
Background
()
func
runSearchCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
allVersions
bool
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
stream
,
res
:=
commands
.
UpdateIndexStreamResponseToCallbackFunction
(
ctx
,
feedback
.
ProgressBar
())
...
...
internal/cli/core/uninstall.go
View file @
24ac0405
...
...
@@ -38,19 +38,18 @@ func initUninstallCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" core uninstall arduino:samd
\n
"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runUninstallCommand
(
srv
,
args
,
preUninstallFlags
)
runUninstallCommand
(
cmd
.
Context
(),
srv
,
args
,
preUninstallFlags
)
},
ValidArgsFunction
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetUninstallableCores
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
arguments
.
GetUninstallableCores
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
},
}
preUninstallFlags
.
AddToCommand
(
uninstallCommand
)
return
uninstallCommand
}
func
runUninstallCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
preUninstallFlags
arguments
.
PrePostScriptsFlags
)
{
func
runUninstallCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
preUninstallFlags
arguments
.
PrePostScriptsFlags
)
{
logrus
.
Info
(
"Executing `arduino-cli core uninstall`"
)
ctx
:=
context
.
Background
()
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
platformsRefs
,
err
:=
arguments
.
ParseReferences
(
ctx
,
srv
,
args
)
...
...
internal/cli/core/update_index.go
View file @
24ac0405
...
...
@@ -36,15 +36,14 @@ func initUpdateIndexCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" core update-index"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runUpdateIndexCommand
(
srv
)
runUpdateIndexCommand
(
cmd
.
Context
(),
srv
)
},
}
return
updateIndexCommand
}
func
runUpdateIndexCommand
(
srv
rpc
.
ArduinoCoreServiceServer
)
{
func
runUpdateIndexCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
logrus
.
Info
(
"Executing `arduino-cli core update-index`"
)
ctx
:=
context
.
Background
()
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
resp
:=
UpdateIndex
(
ctx
,
srv
,
inst
)
...
...
internal/cli/core/upgrade.go
View file @
24ac0405
...
...
@@ -43,16 +43,15 @@ func initUpgradeCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" # "
+
tr
(
"upgrade arduino:samd to the latest version"
)
+
"
\n
"
+
" "
+
os
.
Args
[
0
]
+
" core upgrade arduino:samd"
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runUpgradeCommand
(
srv
,
args
,
postInstallFlags
.
DetectSkipPostInstallValue
(),
postInstallFlags
.
DetectSkipPreUninstallValue
())
runUpgradeCommand
(
cmd
.
Context
(),
srv
,
args
,
postInstallFlags
.
DetectSkipPostInstallValue
(),
postInstallFlags
.
DetectSkipPreUninstallValue
())
},
}
postInstallFlags
.
AddToCommand
(
upgradeCommand
)
return
upgradeCommand
}
func
runUpgradeCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
skipPostInstall
bool
,
skipPreUninstall
bool
)
{
func
runUpgradeCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
skipPostInstall
bool
,
skipPreUninstall
bool
)
{
logrus
.
Info
(
"Executing `arduino-cli core upgrade`"
)
ctx
:=
context
.
Background
()
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
Upgrade
(
ctx
,
srv
,
inst
,
args
,
skipPostInstall
,
skipPreUninstall
)
}
...
...
internal/cli/debug/debug.go
View file @
24ac0405
...
...
@@ -56,7 +56,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" debug -b arduino:samd:mkr1000 -P atmel_ice /home/user/Arduino/MySketch"
,
Args
:
cobra
.
MaximumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runDebugCommand
(
srv
,
args
,
&
portArgs
,
&
fqbnArg
,
interpreter
,
importDir
,
&
programmer
,
printInfo
,
&
profileArg
)
runDebugCommand
(
cmd
.
Context
(),
srv
,
args
,
&
portArgs
,
&
fqbnArg
,
interpreter
,
importDir
,
&
programmer
,
printInfo
,
&
profileArg
)
},
}
...
...
@@ -72,10 +72,9 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
debugCommand
}
func
runDebugCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
portArgs
*
arguments
.
Port
,
fqbnArg
*
arguments
.
Fqbn
,
func
runDebugCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
portArgs
*
arguments
.
Port
,
fqbnArg
*
arguments
.
Fqbn
,
interpreter
string
,
importDir
string
,
programmer
*
arguments
.
Programmer
,
printInfo
bool
,
profileArg
*
arguments
.
Profile
)
{
logrus
.
Info
(
"Executing `arduino-cli debug`"
)
ctx
:=
context
.
Background
()
path
:=
""
if
len
(
args
)
>
0
{
...
...
@@ -103,11 +102,11 @@ func runDebugCommand(srv rpc.ArduinoCoreServiceServer, args []string, portArgs *
fqbnArg
.
Set
(
profile
.
GetFqbn
())
}
fqbn
,
port
:=
arguments
.
CalculateFQBNAndPort
(
portArgs
,
fqbnArg
,
inst
,
srv
,
sk
.
GetDefaultFqbn
(),
sk
.
GetDefaultPort
(),
sk
.
GetDefaultProtocol
())
fqbn
,
port
:=
arguments
.
CalculateFQBNAndPort
(
ctx
,
portArgs
,
fqbnArg
,
inst
,
srv
,
sk
.
GetDefaultFqbn
(),
sk
.
GetDefaultPort
(),
sk
.
GetDefaultProtocol
())
prog
:=
profile
.
GetProgrammer
()
if
prog
==
""
||
programmer
.
GetProgrammer
()
!=
""
{
prog
=
programmer
.
String
(
inst
,
srv
,
fqbn
)
prog
=
programmer
.
String
(
ctx
,
inst
,
srv
,
fqbn
)
}
if
prog
==
""
{
prog
=
sk
.
GetDefaultProgrammer
()
...
...
@@ -125,7 +124,7 @@ func runDebugCommand(srv rpc.ArduinoCoreServiceServer, args []string, portArgs *
if
printInfo
{
if
res
,
err
:=
commands
.
GetDebugConfig
(
c
ontext
.
Background
()
,
debugConfigRequested
);
err
!=
nil
{
if
res
,
err
:=
commands
.
GetDebugConfig
(
c
tx
,
debugConfigRequested
);
err
!=
nil
{
errcode
:=
feedback
.
ErrBadArgument
if
errors
.
Is
(
err
,
&
cmderrors
.
MissingProgrammerError
{})
{
errcode
=
feedback
.
ErrMissingProgrammer
...
...
@@ -145,7 +144,7 @@ func runDebugCommand(srv rpc.ArduinoCoreServiceServer, args []string, portArgs *
if
err
!=
nil
{
feedback
.
FatalError
(
err
,
feedback
.
ErrBadArgument
)
}
if
_
,
err
:=
commands
.
Debug
(
c
ontext
.
Background
()
,
debugConfigRequested
,
in
,
out
,
ctrlc
);
err
!=
nil
{
if
_
,
err
:=
commands
.
Debug
(
c
tx
,
debugConfigRequested
,
in
,
out
,
ctrlc
);
err
!=
nil
{
errcode
:=
feedback
.
ErrGeneric
if
errors
.
Is
(
err
,
&
cmderrors
.
MissingProgrammerError
{})
{
errcode
=
feedback
.
ErrMissingProgrammer
...
...
internal/cli/debug/debug_check.go
View file @
24ac0405
...
...
@@ -41,7 +41,7 @@ func newDebugCheckCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Short
:
tr
(
"Check if the given board/programmer combination supports debugging."
),
Example
:
" "
+
os
.
Args
[
0
]
+
" debug check -b arduino:samd:mkr1000 -P atmel_ice"
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runDebugCheckCommand
(
srv
,
&
portArgs
,
&
fqbnArg
,
interpreter
,
&
programmer
)
runDebugCheckCommand
(
cmd
.
Context
(),
srv
,
&
portArgs
,
&
fqbnArg
,
interpreter
,
&
programmer
)
},
}
fqbnArg
.
AddToCommand
(
debugCheckCommand
,
srv
)
...
...
@@ -51,22 +51,21 @@ func newDebugCheckCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
debugCheckCommand
}
func
runDebugCheckCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
portArgs
*
arguments
.
Port
,
fqbnArg
*
arguments
.
Fqbn
,
interpreter
string
,
programmerArg
*
arguments
.
Programmer
)
{
ctx
:=
context
.
Background
()
func
runDebugCheckCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
portArgs
*
arguments
.
Port
,
fqbnArg
*
arguments
.
Fqbn
,
interpreter
string
,
programmerArg
*
arguments
.
Programmer
)
{
instance
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli debug`"
)
port
,
err
:=
portArgs
.
GetPort
(
instance
,
srv
,
""
,
""
)
port
,
err
:=
portArgs
.
GetPort
(
ctx
,
instance
,
srv
,
""
,
""
)
if
err
!=
nil
{
feedback
.
FatalError
(
err
,
feedback
.
ErrBadArgument
)
}
fqbn
:=
fqbnArg
.
String
()
resp
,
err
:=
commands
.
IsDebugSupported
(
c
ontext
.
Background
()
,
&
rpc
.
IsDebugSupportedRequest
{
resp
,
err
:=
commands
.
IsDebugSupported
(
c
tx
,
&
rpc
.
IsDebugSupportedRequest
{
Instance
:
instance
,
Fqbn
:
fqbn
,
Port
:
port
,
Interpreter
:
interpreter
,
Programmer
:
programmerArg
.
String
(
instance
,
srv
,
fqbn
),
Programmer
:
programmerArg
.
String
(
ctx
,
instance
,
srv
,
fqbn
),
})
if
err
!=
nil
{
feedback
.
FatalError
(
err
,
feedback
.
ErrGeneric
)
...
...
internal/cli/lib/check_deps.go
View file @
24ac0405
...
...
@@ -42,18 +42,17 @@ func initDepsCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" "
+
os
.
Args
[
0
]
+
" lib deps AudioZero@1.0.0 # "
+
tr
(
"for the specific version."
),
Args
:
cobra
.
ExactArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runDepsCommand
(
srv
,
args
,
noOverwrite
)
runDepsCommand
(
cmd
.
Context
(),
srv
,
args
,
noOverwrite
)
},
ValidArgsFunction
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstalledLibraries
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
arguments
.
GetInstalledLibraries
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
},
}
depsCommand
.
Flags
()
.
BoolVar
(
&
noOverwrite
,
"no-overwrite"
,
false
,
tr
(
"Do not try to update library dependencies if already installed."
))
return
depsCommand
}
func
runDepsCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
noOverwrite
bool
)
{
ctx
:=
context
.
Background
()
func
runDepsCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
noOverwrite
bool
)
{
instance
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli lib deps`"
)
...
...
internal/cli/lib/download.go
View file @
24ac0405
...
...
@@ -39,18 +39,17 @@ func initDownloadCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" "
+
os
.
Args
[
0
]
+
" lib download AudioZero@1.0.0 # "
+
tr
(
"for a specific version."
),
Args
:
cobra
.
MinimumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runDownloadCommand
(
srv
,
args
)
runDownloadCommand
(
cmd
.
Context
(),
srv
,
args
)
},
ValidArgsFunction
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstallableLibs
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
arguments
.
GetInstallableLibs
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
},
}
return
downloadCommand
}
func
runDownloadCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
func
runDownloadCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino-cli lib download`"
)
ctx
:=
context
.
Background
()
instance
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
refs
,
err
:=
ParseLibraryReferenceArgsAndAdjustCase
(
ctx
,
srv
,
instance
,
args
)
...
...
internal/cli/lib/examples.go
View file @
24ac0405
...
...
@@ -45,19 +45,18 @@ func initExamplesCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" lib examples Wire"
,
Args
:
cobra
.
MaximumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runExamplesCommand
(
srv
,
args
)
runExamplesCommand
(
cmd
.
Context
(),
srv
,
args
)
},
ValidArgsFunction
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstalledLibraries
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
arguments
.
GetInstalledLibraries
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
},
}
fqbn
.
AddToCommand
(
examplesCommand
,
srv
)
return
examplesCommand
}
func
runExamplesCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
func
runExamplesCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino-cli lib examples`"
)
ctx
:=
context
.
Background
()
instance
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
name
:=
""
...
...
internal/cli/lib/install.go
View file @
24ac0405
...
...
@@ -52,10 +52,10 @@ func initInstallCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configur
" "
+
os
.
Args
[
0
]
+
" lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip
\n
"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runInstallCommand
(
srv
,
args
,
noDeps
,
noOverwrite
,
gitURL
,
zipPath
,
useBuiltinLibrariesDir
,
enableUnsafeInstall
)
runInstallCommand
(
cmd
.
Context
(),
srv
,
args
,
noDeps
,
noOverwrite
,
gitURL
,
zipPath
,
useBuiltinLibrariesDir
,
enableUnsafeInstall
)
},
ValidArgsFunction
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstallableLibs
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
arguments
.
GetInstallableLibs
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
},
}
installCommand
.
Flags
()
.
BoolVar
(
&
noDeps
,
"no-deps"
,
false
,
tr
(
"Do not install dependencies."
))
...
...
@@ -66,8 +66,7 @@ func initInstallCommand(srv rpc.ArduinoCoreServiceServer, settings *rpc.Configur
return
installCommand
}
func
runInstallCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
noDeps
bool
,
noOverwrite
bool
,
gitURL
bool
,
zipPath
bool
,
useBuiltinLibrariesDir
bool
,
enableUnsafeInstall
bool
)
{
ctx
:=
context
.
Background
()
func
runInstallCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
noDeps
bool
,
noOverwrite
bool
,
gitURL
bool
,
zipPath
bool
,
useBuiltinLibrariesDir
bool
,
enableUnsafeInstall
bool
)
{
instance
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli lib install`"
)
...
...
internal/cli/lib/list.go
View file @
24ac0405
...
...
@@ -45,7 +45,7 @@ not listed, they can be listed by adding the --all flag.`),
Example
:
" "
+
os
.
Args
[
0
]
+
" lib list"
,
Args
:
cobra
.
MaximumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
ctx
:=
c
ontext
.
Background
()
ctx
:=
c
md
.
Context
()
instance
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli lib list`"
)
List
(
ctx
,
srv
,
instance
,
args
,
all
,
updatable
)
...
...
internal/cli/lib/search.go
View file @
24ac0405
...
...
@@ -90,7 +90,7 @@ In addition to the fields listed above, QV terms can use these qualifiers:
" "
+
os
.
Args
[
0
]
+
" lib search dependencies=IRremote # "
+
tr
(
"libraries that depend only on
\"
IRremote
\"
"
)
+
"
\n
"
,
Args
:
cobra
.
ArbitraryArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runSearchCommand
(
srv
,
args
,
namesOnly
,
omitReleasesDetails
)
runSearchCommand
(
cmd
.
Context
(),
srv
,
args
,
namesOnly
,
omitReleasesDetails
)
},
}
searchCommand
.
Flags
()
.
BoolVar
(
&
namesOnly
,
"names"
,
false
,
tr
(
"Show library names only."
))
...
...
@@ -101,8 +101,7 @@ In addition to the fields listed above, QV terms can use these qualifiers:
// indexUpdateInterval specifies the time threshold over which indexes are updated
const
indexUpdateInterval
=
60
*
time
.
Minute
func
runSearchCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
namesOnly
bool
,
omitReleasesDetails
bool
)
{
ctx
:=
context
.
Background
()
func
runSearchCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
namesOnly
bool
,
omitReleasesDetails
bool
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli lib search`"
)
...
...
internal/cli/lib/uninstall.go
View file @
24ac0405
...
...
@@ -37,18 +37,17 @@ func initUninstallCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" lib uninstall AudioZero"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runUninstallCommand
(
srv
,
args
)
runUninstallCommand
(
cmd
.
Context
(),
srv
,
args
)
},
ValidArgsFunction
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetUninstallableLibraries
(
c
ontext
.
Background
(),
srv
),
cobra
.
ShellCompDirectiveDefault
return
arguments
.
GetUninstallableLibraries
(
c
md
.
Context
(),
srv
),
cobra
.
ShellCompDirectiveDefault
},
}
return
uninstallCommand
}
func
runUninstallCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
func
runUninstallCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino-cli lib uninstall`"
)
ctx
:=
context
.
Background
()
instance
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
refs
,
err
:=
ParseLibraryReferenceArgsAndAdjustCase
(
ctx
,
srv
,
instance
,
args
)
...
...
internal/cli/lib/update_index.go
View file @
24ac0405
...
...
@@ -36,14 +36,13 @@ func initUpdateIndexCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" lib update-index"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runUpdateIndexCommand
(
srv
)
runUpdateIndexCommand
(
cmd
.
Context
(),
srv
)
},
}
return
updateIndexCommand
}
func
runUpdateIndexCommand
(
srv
rpc
.
ArduinoCoreServiceServer
)
{
ctx
:=
context
.
Background
()
func
runUpdateIndexCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli lib update-index`"
)
...
...
internal/cli/lib/upgrade.go
View file @
24ac0405
...
...
@@ -38,15 +38,14 @@ func initUpgradeCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" "
+
os
.
Args
[
0
]
+
" lib upgrade Audio ArduinoJson"
,
Args
:
cobra
.
ArbitraryArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runUpgradeCommand
(
srv
,
args
)
runUpgradeCommand
(
cmd
.
Context
(),
srv
,
args
)
},
}
return
upgradeCommand
}
func
runUpgradeCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
func
runUpgradeCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
)
{
logrus
.
Info
(
"Executing `arduino-cli lib upgrade`"
)
ctx
:=
context
.
Background
()
instance
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
Upgrade
(
ctx
,
srv
,
instance
,
args
)
}
...
...
internal/cli/monitor/monitor.go
View file @
24ac0405
...
...
@@ -66,7 +66,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
if
len
(
args
)
>
0
{
sketchPath
=
args
[
0
]
}
runMonitorCmd
(
srv
,
&
portArgs
,
&
fqbnArg
,
&
profileArg
,
sketchPath
,
configs
,
describe
,
timestamp
,
quiet
,
raw
)
runMonitorCmd
(
cmd
.
Context
(),
srv
,
&
portArgs
,
&
fqbnArg
,
&
profileArg
,
sketchPath
,
configs
,
describe
,
timestamp
,
quiet
,
raw
)
},
}
portArgs
.
AddToCommand
(
monitorCommand
,
srv
)
...
...
@@ -81,12 +81,11 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
}
func
runMonitorCmd
(
srv
rpc
.
ArduinoCoreServiceServer
,
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
portArgs
*
arguments
.
Port
,
fqbnArg
*
arguments
.
Fqbn
,
profileArg
*
arguments
.
Profile
,
sketchPathArg
string
,
configs
[]
string
,
describe
,
timestamp
,
quiet
,
raw
bool
,
)
{
logrus
.
Info
(
"Executing `arduino-cli monitor`"
)
ctx
:=
context
.
Background
()
if
!
feedback
.
HasConsole
()
{
quiet
=
true
...
...
@@ -139,10 +138,10 @@ func runMonitorCmd(
case
sketch
.
GetDefaultFqbn
()
!=
""
:
fqbn
=
sketch
.
GetDefaultFqbn
()
default
:
fqbn
,
_
=
portArgs
.
DetectFQBN
(
inst
,
srv
)
fqbn
,
_
=
portArgs
.
DetectFQBN
(
ctx
,
inst
,
srv
)
}
portAddress
,
portProtocol
,
err
:=
portArgs
.
GetPortAddressAndProtocol
(
inst
,
srv
,
defaultPort
,
defaultProtocol
)
portAddress
,
portProtocol
,
err
:=
portArgs
.
GetPortAddressAndProtocol
(
ctx
,
inst
,
srv
,
defaultPort
,
defaultProtocol
)
if
err
!=
nil
{
feedback
.
FatalError
(
err
,
feedback
.
ErrGeneric
)
}
...
...
internal/cli/outdated/outdated.go
View file @
24ac0405
...
...
@@ -46,15 +46,14 @@ that can be upgraded. If nothing needs to be updated the output is empty.`),
Example
:
" "
+
os
.
Args
[
0
]
+
" outdated
\n
"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runOutdatedCommand
(
srv
)
runOutdatedCommand
(
cmd
.
Context
(),
srv
)
},
}
return
outdatedCommand
}
func
runOutdatedCommand
(
srv
rpc
.
ArduinoCoreServiceServer
)
{
func
runOutdatedCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
logrus
.
Info
(
"Executing `arduino-cli outdated`"
)
ctx
:=
context
.
Background
()
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
Outdated
(
ctx
,
srv
,
inst
)
}
...
...
internal/cli/sketch/archive.go
View file @
24ac0405
...
...
@@ -43,7 +43,7 @@ func initArchiveCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
" "
+
os
.
Args
[
0
]
+
" archive /home/user/Arduino/MySketch /home/user/MySketchArchive.zip"
,
Args
:
cobra
.
MaximumNArgs
(
2
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runArchiveCommand
(
srv
,
args
,
includeBuildDir
,
overwrite
)
runArchiveCommand
(
cmd
.
Context
(),
srv
,
args
,
includeBuildDir
,
overwrite
)
},
}
...
...
@@ -53,9 +53,8 @@ func initArchiveCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
archiveCommand
}
func
runArchiveCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
includeBuildDir
bool
,
overwrite
bool
)
{
func
runArchiveCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
includeBuildDir
bool
,
overwrite
bool
)
{
logrus
.
Info
(
"Executing `arduino-cli sketch archive`"
)
ctx
:=
context
.
Background
()
sketchPathArg
:=
""
if
len
(
args
)
>
0
{
sketchPathArg
=
args
[
0
]
...
...
internal/cli/sketch/new.go
View file @
24ac0405
...
...
@@ -38,7 +38,7 @@ func initNewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" sketch new MultiBlinker"
,
Args
:
cobra
.
ExactArgs
(
1
),
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runNewCommand
(
srv
,
args
,
overwrite
)
runNewCommand
(
cmd
.
Context
(),
srv
,
args
,
overwrite
)
},
}
...
...
@@ -47,8 +47,7 @@ func initNewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
newCommand
}
func
runNewCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
overwrite
bool
)
{
ctx
:=
context
.
Background
()
func
runNewCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
overwrite
bool
)
{
logrus
.
Info
(
"Executing `arduino-cli sketch new`"
)
// Trim to avoid issues if user creates a sketch adding the .ino extesion to the name
inputSketchName
:=
args
[
0
]
...
...
internal/cli/update/update.go
View file @
24ac0405
...
...
@@ -41,16 +41,15 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" update"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runUpdateCommand
(
srv
,
showOutdated
)
runUpdateCommand
(
cmd
.
Context
(),
srv
,
showOutdated
)
},
}
updateCommand
.
Flags
()
.
BoolVar
(
&
showOutdated
,
"show-outdated"
,
false
,
tr
(
"Show outdated cores and libraries after index update"
))
return
updateCommand
}
func
runUpdateCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
showOutdated
bool
)
{
func
runUpdateCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
showOutdated
bool
)
{
logrus
.
Info
(
"Executing `arduino-cli update`"
)
ctx
:=
context
.
Background
()
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
lib
.
UpdateIndex
(
ctx
,
srv
,
inst
)
...
...
internal/cli/upgrade/upgrade.go
View file @
24ac0405
...
...
@@ -41,15 +41,14 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" upgrade"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runUpgradeCommand
(
srv
,
postInstallFlags
.
DetectSkipPostInstallValue
(),
postInstallFlags
.
DetectSkipPreUninstallValue
())
runUpgradeCommand
(
cmd
.
Context
(),
srv
,
postInstallFlags
.
DetectSkipPostInstallValue
(),
postInstallFlags
.
DetectSkipPreUninstallValue
())
},
}
postInstallFlags
.
AddToCommand
(
upgradeCommand
)
return
upgradeCommand
}
func
runUpgradeCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
skipPostInstall
bool
,
skipPreUninstall
bool
)
{
ctx
:=
context
.
Background
()
func
runUpgradeCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
skipPostInstall
bool
,
skipPreUninstall
bool
)
{
inst
:=
instance
.
CreateAndInit
(
ctx
,
srv
)
logrus
.
Info
(
"Executing `arduino-cli upgrade`"
)
lib
.
Upgrade
(
ctx
,
srv
,
inst
,
[]
string
{})
...
...
internal/cli/upload/upload.go
View file @
24ac0405
...
...
@@ -63,7 +63,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
arguments
.
CheckFlagsConflicts
(
cmd
,
"input-file"
,
"input-dir"
)
},
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runUploadCommand
(
srv
,
args
,
uploadFields
)
runUploadCommand
(
cmd
.
Context
(),
srv
,
args
,
uploadFields
)
},
}
...
...
@@ -81,11 +81,9 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
return
uploadCommand
}
func
runUploadCommand
(
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
uploadFieldsArgs
map
[
string
]
string
)
{
func
runUploadCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
,
args
[]
string
,
uploadFieldsArgs
map
[
string
]
string
)
{
logrus
.
Info
(
"Executing `arduino-cli upload`"
)
ctx
:=
context
.
Background
()
path
:=
""
if
len
(
args
)
>
0
{
path
=
args
[
0
]
...
...
@@ -116,7 +114,7 @@ func runUploadCommand(srv rpc.ArduinoCoreServiceServer, args []string, uploadFie
defaultFQBN
:=
sketch
.
GetDefaultFqbn
()
defaultAddress
:=
sketch
.
GetDefaultPort
()
defaultProtocol
:=
sketch
.
GetDefaultProtocol
()
fqbn
,
port
:=
arguments
.
CalculateFQBNAndPort
(
&
portArgs
,
&
fqbnArg
,
inst
,
srv
,
defaultFQBN
,
defaultAddress
,
defaultProtocol
)
fqbn
,
port
:=
arguments
.
CalculateFQBNAndPort
(
ctx
,
&
portArgs
,
&
fqbnArg
,
inst
,
srv
,
defaultFQBN
,
defaultAddress
,
defaultProtocol
)
userFieldRes
,
err
:=
srv
.
SupportedUserFields
(
ctx
,
&
rpc
.
SupportedUserFieldsRequest
{
Instance
:
inst
,
...
...
@@ -179,7 +177,7 @@ func runUploadCommand(srv rpc.ArduinoCoreServiceServer, args []string, uploadFie
prog
:=
profile
.
GetProgrammer
()
if
prog
==
""
||
programmer
.
GetProgrammer
()
!=
""
{
prog
=
programmer
.
String
(
inst
,
srv
,
fqbn
)
prog
=
programmer
.
String
(
ctx
,
inst
,
srv
,
fqbn
)
}
if
prog
==
""
{
prog
=
sketch
.
GetDefaultProgrammer
()
...
...
internal/cli/version/version.go
View file @
24ac0405
...
...
@@ -40,13 +40,13 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
Example
:
" "
+
os
.
Args
[
0
]
+
" version"
,
Args
:
cobra
.
NoArgs
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
runVersionCommand
(
srv
)
runVersionCommand
(
cmd
.
Context
(),
srv
)
},
}
return
versionCommand
}
func
runVersionCommand
(
srv
rpc
.
ArduinoCoreServiceServer
)
{
func
runVersionCommand
(
ctx
context
.
Context
,
srv
rpc
.
ArduinoCoreServiceServer
)
{
logrus
.
Info
(
"Executing `arduino-cli version`"
)
info
:=
version
.
VersionInfo
...
...
@@ -58,7 +58,7 @@ func runVersionCommand(srv rpc.ArduinoCoreServiceServer) {
}
latestVersion
:=
""
res
,
err
:=
srv
.
CheckForArduinoCLIUpdates
(
c
ontext
.
Background
()
,
&
rpc
.
CheckForArduinoCLIUpdatesRequest
{})
res
,
err
:=
srv
.
CheckForArduinoCLIUpdates
(
c
tx
,
&
rpc
.
CheckForArduinoCLIUpdatesRequest
{})
if
err
!=
nil
{
feedback
.
Warning
(
"Failed to check for updates: "
+
err
.
Error
())
}
else
{
...
...
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