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
59436ca6
Commit
59436ca6
authored
Oct 26, 2018
by
Cristian Maglie
Committed by
Cristian Maglie
Oct 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added --input flag to 'upload' command.
Also simplified configuration creation for upload command.
parent
9170d1fa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
35 deletions
+44
-35
commands/upload/upload.go
commands/upload/upload.go
+44
-35
No files found.
commands/upload/upload.go
View file @
59436ca6
...
...
@@ -45,13 +45,20 @@ func InitCommand() *cobra.Command {
Args
:
cobra
.
MaximumNArgs
(
1
),
Run
:
run
,
}
uploadCommand
.
Flags
()
.
StringVarP
(
&
flags
.
fqbn
,
"fqbn"
,
"b"
,
""
,
uploadCommand
.
Flags
()
.
StringVarP
(
&
flags
.
fqbn
,
"fqbn"
,
"b"
,
""
,
"Fully Qualified Board Name, e.g.: arduino:avr:uno"
)
uploadCommand
.
Flags
()
.
StringVarP
(
&
flags
.
port
,
"port"
,
"p"
,
""
,
uploadCommand
.
Flags
()
.
StringVarP
(
&
flags
.
port
,
"port"
,
"p"
,
""
,
"Upload port, e.g.: COM10 or /dev/ttyACM0"
)
uploadCommand
.
Flags
()
.
BoolVarP
(
&
flags
.
verify
,
"verify"
,
"t"
,
false
,
uploadCommand
.
Flags
()
.
StringVarP
(
&
flags
.
importFile
,
"input"
,
"i"
,
""
,
"Input file to be uploaded."
)
uploadCommand
.
Flags
()
.
BoolVarP
(
&
flags
.
verify
,
"verify"
,
"t"
,
false
,
"Verify uploaded binary after the upload."
)
uploadCommand
.
Flags
()
.
BoolVarP
(
&
flags
.
verbose
,
"verbose"
,
"v"
,
false
,
uploadCommand
.
Flags
()
.
BoolVarP
(
&
flags
.
verbose
,
"verbose"
,
"v"
,
false
,
"Optional, turns on verbose mode."
)
return
uploadCommand
}
...
...
@@ -61,6 +68,7 @@ var flags struct {
port
string
verbose
bool
verify
bool
importFile
string
}
func
run
(
command
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -81,42 +89,28 @@ func run(command *cobra.Command, args []string) {
os
.
Exit
(
commands
.
ErrBadCall
)
}
fqbn
:=
flags
.
fqbn
if
fqbn
==
""
&&
sketch
!=
nil
{
fqbn
=
sketch
.
Metadata
.
CPU
.
Fqbn
if
flags
.
fqbn
==
""
&&
sketch
!=
nil
{
flags
.
fqbn
=
sketch
.
Metadata
.
CPU
.
Fqbn
}
if
fqbn
==
""
{
if
f
lags
.
f
qbn
==
""
{
formatter
.
PrintErrorMessage
(
"No Fully Qualified Board Name provided."
)
os
.
Exit
(
commands
.
ErrBadCall
)
}
fqbn
Parts
:=
strings
.
Split
(
fqbn
,
":"
)
if
len
(
fqbnParts
)
<
3
||
len
(
fqbnParts
)
>
4
{
formatter
.
PrintError
Message
(
"Fully Qualified Board Name has incorrect format
."
)
fqbn
,
err
:=
cores
.
ParseFQBN
(
flags
.
fqbn
)
if
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Invalid FQBN
."
)
os
.
Exit
(
commands
.
ErrBadCall
)
}
pm
:=
commands
.
InitPackageManager
()
// Find target board
board
,
err
:=
pm
.
FindBoardWith
FQBN
(
fqbn
)
// Find target board
and board properties
_
,
_
,
board
,
boardProperties
,
_
,
err
:=
pm
.
Resolve
FQBN
(
fqbn
)
if
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Invalid FQBN."
)
os
.
Exit
(
commands
.
ErrBadCall
)
}
// Create board configuration
var
boardProperties
*
properties
.
Map
if
len
(
fqbnParts
)
==
3
{
boardProperties
=
board
.
Properties
}
else
{
if
props
,
err
:=
board
.
GeneratePropertiesForConfiguration
(
fqbnParts
[
3
]);
err
!=
nil
{
formatter
.
PrintError
(
err
,
"Invalid FQBN."
)
os
.
Exit
(
commands
.
ErrBadCall
)
}
else
{
boardProperties
=
props
}
}
// Load programmer tool
uploadToolID
,
have
:=
boardProperties
.
GetOk
(
"upload.tool"
)
if
!
have
||
uploadToolID
==
""
{
...
...
@@ -194,12 +188,27 @@ func run(command *cobra.Command, args []string) {
}
// Set path to compiled binary
// FIXME: refactor this should be made into a function
fqbn
=
strings
.
Replace
(
fqbn
,
":"
,
"."
,
-
1
)
uploadProperties
.
Set
(
"build.path"
,
sketch
.
FullPath
)
uploadProperties
.
Set
(
"build.project_name"
,
sketch
.
Name
+
"."
+
fqbn
)
// Make the filename without the FQBN configs part
fqbn
.
Configs
=
properties
.
NewMap
()
fqbnSuffix
:=
strings
.
Replace
(
fqbn
.
String
(),
":"
,
"."
,
-
1
)
ext
:=
filepath
.
Ext
(
uploadProperties
.
ExpandPropsInString
(
"{recipe.output.tmp_file}"
))
if
_
,
err
:=
os
.
Stat
(
filepath
.
Join
(
sketch
.
FullPath
,
sketch
.
Name
+
"."
+
fqbn
+
ext
));
err
!=
nil
{
var
importPath
*
paths
.
Path
var
importFile
string
if
flags
.
importFile
==
""
{
importPath
=
paths
.
New
(
sketch
.
FullPath
)
importFile
=
sketch
.
Name
+
"."
+
fqbnSuffix
}
else
{
importPath
=
paths
.
New
(
flags
.
importFile
)
.
Parent
()
importFile
=
paths
.
New
(
flags
.
importFile
)
.
Base
()
if
strings
.
HasSuffix
(
importFile
,
ext
)
{
importFile
=
importFile
[
:
len
(
importFile
)
-
len
(
ext
)]
}
}
uploadProperties
.
SetPath
(
"build.path"
,
importPath
)
uploadProperties
.
Set
(
"build.project_name"
,
importFile
)
if
_
,
err
:=
os
.
Stat
(
filepath
.
Join
(
sketch
.
FullPath
,
importFile
+
ext
));
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
formatter
.
PrintErrorMessage
(
"Compiled sketch not found. Please compile first."
)
}
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