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
9131edb8
Commit
9131edb8
authored
Nov 18, 2021
by
Umberto Baldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor upload command to use code from the arguments package
parent
ea0334cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
25 deletions
+14
-25
cli/upload/upload.go
cli/upload/upload.go
+14
-25
No files found.
cli/upload/upload.go
View file @
9131edb8
...
...
@@ -30,13 +30,13 @@ import (
)
var
(
fqbn
string
fqbn
arguments
.
Fqbn
port
arguments
.
Port
verbose
bool
verify
bool
importDir
string
importFile
string
programmer
string
programmer
arguments
.
Programmer
dryRun
bool
tr
=
i18n
.
Tr
)
...
...
@@ -49,36 +49,25 @@ func NewCommand() *cobra.Command {
Long
:
tr
(
"Upload Arduino sketches. This does NOT compile the sketch prior to upload."
),
Example
:
" "
+
os
.
Args
[
0
]
+
" upload /home/user/Arduino/MySketch"
,
Args
:
cobra
.
MaximumNArgs
(
1
),
PreRun
:
checkFlagsConflicts
,
Run
:
run
,
PreRun
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
arguments
.
CheckFlagsConflicts
(
cmd
,
"input-file"
,
"input-dir"
)
},
Run
:
runUploadCommand
,
}
uploadCommand
.
Flags
()
.
StringVarP
(
&
fqbn
,
"fqbn"
,
"b"
,
""
,
tr
(
"Fully Qualified Board Name, e.g.: arduino:avr:uno"
))
uploadCommand
.
RegisterFlagCompletionFunc
(
"fqbn"
,
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstalledBoards
(),
cobra
.
ShellCompDirectiveDefault
})
fqbn
.
AddToCommand
(
uploadCommand
)
port
.
AddToCommand
(
uploadCommand
)
uploadCommand
.
Flags
()
.
StringVarP
(
&
importDir
,
"input-dir"
,
""
,
""
,
tr
(
"Directory containing binaries to upload."
))
uploadCommand
.
Flags
()
.
StringVarP
(
&
importFile
,
"input-file"
,
"i"
,
""
,
tr
(
"Binary file to upload."
))
uploadCommand
.
Flags
()
.
BoolVarP
(
&
verify
,
"verify"
,
"t"
,
false
,
tr
(
"Verify uploaded binary after the upload."
))
uploadCommand
.
Flags
()
.
BoolVarP
(
&
verbose
,
"verbose"
,
"v"
,
false
,
tr
(
"Optional, turns on verbose mode."
))
uploadCommand
.
Flags
()
.
StringVarP
(
&
programmer
,
"programmer"
,
"P"
,
""
,
tr
(
"Optional, use the specified programmer to upload."
))
uploadCommand
.
RegisterFlagCompletionFunc
(
"programmer"
,
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstalledProgrammers
(),
cobra
.
ShellCompDirectiveDefault
})
programmer
.
AddToCommand
(
uploadCommand
)
uploadCommand
.
Flags
()
.
BoolVar
(
&
dryRun
,
"dry-run"
,
false
,
tr
(
"Do not perform the actual upload, just log out actions"
))
uploadCommand
.
Flags
()
.
MarkHidden
(
"dry-run"
)
return
uploadCommand
}
func
checkFlagsConflicts
(
command
*
cobra
.
Command
,
args
[]
string
)
{
if
importFile
!=
""
&&
importDir
!=
""
{
feedback
.
Errorf
(
tr
(
"error: %s and %s flags cannot be used together"
,
"--input-file"
,
"--input-dir"
))
os
.
Exit
(
errorcodes
.
ErrBadArgument
)
}
}
func
run
(
command
*
cobra
.
Command
,
args
[]
string
)
{
func
runUploadCommand
(
command
*
cobra
.
Command
,
args
[]
string
)
{
instance
:=
instance
.
CreateAndInit
()
path
:=
""
...
...
@@ -90,15 +79,15 @@ func run(command *cobra.Command, args []string) {
sk
:=
arguments
.
NewSketch
(
sketchPath
)
discoveryPort
:=
port
.
GetDiscoveryPort
(
instance
,
sk
)
if
fqbn
==
""
&&
sk
!=
nil
&&
sk
.
Metadata
!=
nil
{
if
fqbn
.
String
()
==
""
&&
sk
!=
nil
&&
sk
.
Metadata
!=
nil
{
// If the user didn't specify an FQBN and a sketch.json file is present
// read it from there.
fqbn
=
sk
.
Metadata
.
CPU
.
Fqbn
fqbn
.
Set
(
sk
.
Metadata
.
CPU
.
Fqbn
)
}
userFieldRes
,
err
:=
upload
.
SupportedUserFields
(
context
.
Background
(),
&
rpc
.
SupportedUserFieldsRequest
{
Instance
:
instance
,
Fqbn
:
fqbn
,
Fqbn
:
fqbn
.
String
()
,
Protocol
:
discoveryPort
.
Protocol
,
})
if
err
!=
nil
{
...
...
@@ -118,14 +107,14 @@ func run(command *cobra.Command, args []string) {
if
_
,
err
:=
upload
.
Upload
(
context
.
Background
(),
&
rpc
.
UploadRequest
{
Instance
:
instance
,
Fqbn
:
fqbn
,
Fqbn
:
fqbn
.
String
()
,
SketchPath
:
path
,
Port
:
discoveryPort
.
ToRPC
(),
Verbose
:
verbose
,
Verify
:
verify
,
ImportFile
:
importFile
,
ImportDir
:
importDir
,
Programmer
:
programmer
,
Programmer
:
programmer
.
String
()
,
DryRun
:
dryRun
,
UserFields
:
fields
,
},
os
.
Stdout
,
os
.
Stderr
);
err
!=
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