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 (
...
@@ -30,13 +30,13 @@ import (
)
)
var
(
var
(
fqbn
string
fqbn
arguments
.
Fqbn
port
arguments
.
Port
port
arguments
.
Port
verbose
bool
verbose
bool
verify
bool
verify
bool
importDir
string
importDir
string
importFile
string
importFile
string
programmer
string
programmer
arguments
.
Programmer
dryRun
bool
dryRun
bool
tr
=
i18n
.
Tr
tr
=
i18n
.
Tr
)
)
...
@@ -49,36 +49,25 @@ func NewCommand() *cobra.Command {
...
@@ -49,36 +49,25 @@ func NewCommand() *cobra.Command {
Long
:
tr
(
"Upload Arduino sketches. This does NOT compile the sketch prior to upload."
),
Long
:
tr
(
"Upload Arduino sketches. This does NOT compile the sketch prior to upload."
),
Example
:
" "
+
os
.
Args
[
0
]
+
" upload /home/user/Arduino/MySketch"
,
Example
:
" "
+
os
.
Args
[
0
]
+
" upload /home/user/Arduino/MySketch"
,
Args
:
cobra
.
MaximumNArgs
(
1
),
Args
:
cobra
.
MaximumNArgs
(
1
),
PreRun
:
checkFlagsConflicts
,
PreRun
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
Run
:
run
,
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"
))
fqbn
.
AddToCommand
(
uploadCommand
)
uploadCommand
.
RegisterFlagCompletionFunc
(
"fqbn"
,
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstalledBoards
(),
cobra
.
ShellCompDirectiveDefault
})
port
.
AddToCommand
(
uploadCommand
)
port
.
AddToCommand
(
uploadCommand
)
uploadCommand
.
Flags
()
.
StringVarP
(
&
importDir
,
"input-dir"
,
""
,
""
,
tr
(
"Directory containing binaries to upload."
))
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
()
.
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
(
&
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
()
.
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."
))
programmer
.
AddToCommand
(
uploadCommand
)
uploadCommand
.
RegisterFlagCompletionFunc
(
"programmer"
,
func
(
cmd
*
cobra
.
Command
,
args
[]
string
,
toComplete
string
)
([]
string
,
cobra
.
ShellCompDirective
)
{
return
arguments
.
GetInstalledProgrammers
(),
cobra
.
ShellCompDirectiveDefault
})
uploadCommand
.
Flags
()
.
BoolVar
(
&
dryRun
,
"dry-run"
,
false
,
tr
(
"Do not perform the actual upload, just log out actions"
))
uploadCommand
.
Flags
()
.
BoolVar
(
&
dryRun
,
"dry-run"
,
false
,
tr
(
"Do not perform the actual upload, just log out actions"
))
uploadCommand
.
Flags
()
.
MarkHidden
(
"dry-run"
)
uploadCommand
.
Flags
()
.
MarkHidden
(
"dry-run"
)
return
uploadCommand
return
uploadCommand
}
}
func
checkFlagsConflicts
(
command
*
cobra
.
Command
,
args
[]
string
)
{
func
runUploadCommand
(
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
)
{
instance
:=
instance
.
CreateAndInit
()
instance
:=
instance
.
CreateAndInit
()
path
:=
""
path
:=
""
...
@@ -90,15 +79,15 @@ func run(command *cobra.Command, args []string) {
...
@@ -90,15 +79,15 @@ func run(command *cobra.Command, args []string) {
sk
:=
arguments
.
NewSketch
(
sketchPath
)
sk
:=
arguments
.
NewSketch
(
sketchPath
)
discoveryPort
:=
port
.
GetDiscoveryPort
(
instance
,
sk
)
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
// If the user didn't specify an FQBN and a sketch.json file is present
// read it from there.
// read it from there.
fqbn
=
sk
.
Metadata
.
CPU
.
Fqbn
fqbn
.
Set
(
sk
.
Metadata
.
CPU
.
Fqbn
)
}
}
userFieldRes
,
err
:=
upload
.
SupportedUserFields
(
context
.
Background
(),
&
rpc
.
SupportedUserFieldsRequest
{
userFieldRes
,
err
:=
upload
.
SupportedUserFields
(
context
.
Background
(),
&
rpc
.
SupportedUserFieldsRequest
{
Instance
:
instance
,
Instance
:
instance
,
Fqbn
:
fqbn
,
Fqbn
:
fqbn
.
String
()
,
Protocol
:
discoveryPort
.
Protocol
,
Protocol
:
discoveryPort
.
Protocol
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -118,14 +107,14 @@ func run(command *cobra.Command, args []string) {
...
@@ -118,14 +107,14 @@ func run(command *cobra.Command, args []string) {
if
_
,
err
:=
upload
.
Upload
(
context
.
Background
(),
&
rpc
.
UploadRequest
{
if
_
,
err
:=
upload
.
Upload
(
context
.
Background
(),
&
rpc
.
UploadRequest
{
Instance
:
instance
,
Instance
:
instance
,
Fqbn
:
fqbn
,
Fqbn
:
fqbn
.
String
()
,
SketchPath
:
path
,
SketchPath
:
path
,
Port
:
discoveryPort
.
ToRPC
(),
Port
:
discoveryPort
.
ToRPC
(),
Verbose
:
verbose
,
Verbose
:
verbose
,
Verify
:
verify
,
Verify
:
verify
,
ImportFile
:
importFile
,
ImportFile
:
importFile
,
ImportDir
:
importDir
,
ImportDir
:
importDir
,
Programmer
:
programmer
,
Programmer
:
programmer
.
String
()
,
DryRun
:
dryRun
,
DryRun
:
dryRun
,
UserFields
:
fields
,
UserFields
:
fields
,
},
os
.
Stdout
,
os
.
Stderr
);
err
!=
nil
{
},
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