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
f61c1bc3
Unverified
Commit
f61c1bc3
authored
Aug 24, 2021
by
Cristian Maglie
Committed by
GitHub
Aug 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[skip-changelog] Simplified getUserFields method (#1412)
parent
9cc4eea7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
77 deletions
+53
-77
commands/upload/upload.go
commands/upload/upload.go
+4
-18
commands/upload/upload_test.go
commands/upload/upload_test.go
+2
-8
i18n/data/en.po
i18n/data/en.po
+40
-44
i18n/rice-box.go
i18n/rice-box.go
+7
-7
No files found.
commands/upload/upload.go
View file @
f61c1bc3
...
...
@@ -20,7 +20,6 @@ import (
"fmt"
"io"
"path/filepath"
"strconv"
"strings"
"github.com/arduino/arduino-cli/arduino/cores"
...
...
@@ -67,13 +66,8 @@ func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsReques
return
nil
,
err
}
userFields
,
err
:=
getUserFields
(
toolID
,
platformRelease
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
rpc
.
SupportedUserFieldsResponse
{
UserFields
:
userFields
,
UserFields
:
getUserFields
(
toolID
,
platformRelease
)
,
},
nil
}
...
...
@@ -95,7 +89,7 @@ func getToolID(props *properties.Map, action, protocol string) (string, error) {
// getUserFields return all user fields supported by the tools specified.
// Returns error only in case the secret property is not a valid boolean.
func
getUserFields
(
toolID
string
,
platformRelease
*
cores
.
PlatformRelease
)
([]
*
rpc
.
UserField
,
error
)
{
func
getUserFields
(
toolID
string
,
platformRelease
*
cores
.
PlatformRelease
)
[]
*
rpc
.
UserField
{
userFields
:=
[]
*
rpc
.
UserField
{}
fields
:=
platformRelease
.
Properties
.
SubTree
(
fmt
.
Sprintf
(
"tools.%s.upload.field"
,
toolID
))
keys
:=
fields
.
FirstLevelKeys
()
...
...
@@ -105,15 +99,7 @@ func getUserFields(toolID string, platformRelease *cores.PlatformRelease) ([]*rp
if
len
(
value
)
>
50
{
value
=
fmt
.
Sprintf
(
"%s…"
,
value
[
:
49
])
}
secretProp
:=
fmt
.
Sprintf
(
"%s.secret"
,
key
)
secret
,
ok
:=
fields
.
GetOk
(
secretProp
)
if
!
ok
{
secret
=
"false"
}
isSecret
,
err
:=
strconv
.
ParseBool
(
secret
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
tr
(
"parsing %s, property is not a boolean"
),
fmt
.
Sprintf
(
`"tools.%s.upload.field.%s.secret"`
,
toolID
,
key
))
}
isSecret
:=
fields
.
GetBoolean
(
fmt
.
Sprintf
(
"%s.secret"
,
key
))
userFields
=
append
(
userFields
,
&
rpc
.
UserField
{
ToolId
:
toolID
,
Name
:
key
,
...
...
@@ -122,7 +108,7 @@ func getUserFields(toolID string, platformRelease *cores.PlatformRelease) ([]*rp
})
}
return
userFields
,
nil
return
userFields
}
// Upload FIXMEDOC
...
...
commands/upload/upload_test.go
View file @
f61c1bc3
...
...
@@ -282,8 +282,7 @@ tools.arduino_ota.upload.field.password.secret=true`))
platformRelease
.
Properties
=
props
userFields
,
err
:=
getUserFields
(
"avrdude"
,
platformRelease
)
require
.
NoError
(
t
,
err
)
userFields
:=
getUserFields
(
"avrdude"
,
platformRelease
)
require
.
Len
(
t
,
userFields
,
2
)
require
.
Equal
(
t
,
userFields
[
0
]
.
ToolId
,
"avrdude"
)
require
.
Equal
(
t
,
userFields
[
0
]
.
Name
,
"username"
)
...
...
@@ -300,17 +299,12 @@ tools.arduino_ota.upload.field.password.secret=THIS_IS_NOT_A_BOOLEAN`))
require
.
NoError
(
t
,
err
)
platformRelease
.
Properties
=
props
userFields
,
err
=
getUserFields
(
"arduino_ota"
,
platformRelease
)
require
.
Nil
(
t
,
userFields
)
require
.
EqualError
(
t
,
err
,
`parsing "tools.arduino_ota.upload.field.password.secret", property is not a boolean`
)
props
,
err
=
properties
.
LoadFromBytes
([]
byte
(
`
tools.arduino_ota.upload.field.some_field=This is a really long label that ideally must never be set by any platform
`
))
require
.
NoError
(
t
,
err
)
platformRelease
.
Properties
=
props
userFields
,
err
=
getUserFields
(
"arduino_ota"
,
platformRelease
)
require
.
NoError
(
t
,
err
)
userFields
=
getUserFields
(
"arduino_ota"
,
platformRelease
)
require
.
Len
(
t
,
userFields
,
1
)
require
.
Equal
(
t
,
userFields
[
0
]
.
ToolId
,
"arduino_ota"
)
require
.
Equal
(
t
,
userFields
[
0
]
.
Name
,
"some_field"
)
...
...
i18n/data/en.po
View file @
f61c1bc3
...
...
@@ -41,7 +41,7 @@ msgstr "%[1]s, protocol version: %[2]d"
msgid "%s already downloaded"
msgstr "%s already downloaded"
#: commands/upload/upload.go:5
41
#: commands/upload/upload.go:5
28
msgid "%s and %s cannot be used together"
msgstr "%s and %s cannot be used together"
...
...
@@ -298,7 +298,7 @@ msgstr "Cannot get command line for tool"
msgid "Cannot get executable path: %v"
msgstr "Cannot get executable path: %v"
#: commands/upload/upload.go:4
31
#: commands/upload/upload.go:4
18
msgid "Cannot perform port reset: %s"
msgstr "Cannot perform port reset: %s"
...
...
@@ -1243,7 +1243,7 @@ msgstr "No platforms matching your search."
msgid "No updates available."
msgstr "No updates available."
#: commands/upload/upload.go:4
20
#: commands/upload/upload.go:4
07
msgid "No upload port found, using %s as fallback"
msgstr "No upload port found, using %s as fallback"
...
...
@@ -1354,7 +1354,7 @@ msgstr "Path to the file where logs will be written."
msgid "Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS."
msgstr "Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS."
#: commands/upload/upload.go:3
99
#: commands/upload/upload.go:3
86
msgid "Performing 1200-bps touch reset on serial port %s"
msgstr "Performing 1200-bps touch reset on serial port %s"
...
...
@@ -1646,7 +1646,7 @@ msgstr "Sketches with .pde extension are deprecated, please rename the following
msgid "Skip linking of final executable."
msgstr "Skip linking of final executable."
#: commands/upload/upload.go:3
92
#: commands/upload/upload.go:3
79
msgid "Skipping 1200-bps touch reset: no serial port selected!"
msgstr "Skipping 1200-bps touch reset: no serial port selected!"
...
...
@@ -1900,7 +1900,7 @@ msgstr "Upload Arduino sketches. This does NOT compile the sketch prior to uploa
msgid "Upload port address, e.g.: COM3 or /dev/ttyACM2"
msgstr "Upload port address, e.g.: COM3 or /dev/ttyACM2"
#: commands/upload/upload.go:4
17
#: commands/upload/upload.go:4
04
msgid "Upload port found on %s"
msgstr "Upload port found on %s"
...
...
@@ -2018,7 +2018,7 @@ msgstr "WARNING: cannot run post install: %s"
msgid "WARNING: library {0} claims to run on {1} architecture(s) and may be incompatible with your current board which runs on {2} architecture(s)."
msgstr "WARNING: library {0} claims to run on {1} architecture(s) and may be incompatible with your current board which runs on {2} architecture(s)."
#: commands/upload/upload.go:
406
#: commands/upload/upload.go:
393
msgid "Waiting for upload port..."
msgstr "Waiting for upload port..."
...
...
@@ -2030,7 +2030,7 @@ msgstr "Warning: Board {0}:{1}:{2} doesn''t define a %s preference. Auto-set to:
msgid "Warning: platform.txt from core '{0}' contains deprecated {1}, automatically converted to {2}. Consider upgrading this core."
msgstr "Warning: platform.txt from core '{0}' contains deprecated {1}, automatically converted to {2}. Consider upgrading this core."
#: commands/upload/upload.go:
301
#: commands/upload/upload.go:
288
msgid "Warning: tool '%s' is not installed. It might not be available for your OS."
msgstr "Warning: tool '%s' is not installed. It might not be available for your OS."
...
...
@@ -2059,7 +2059,7 @@ msgstr "Writing config file: %v"
msgid "[DEPRECATED] %s"
msgstr "[DEPRECATED] %s"
#: commands/upload/upload.go:3
15
#: commands/upload/upload.go:3
02
msgid "a programmer is required to upload for this board"
msgstr "a programmer is required to upload for this board"
...
...
@@ -2083,11 +2083,11 @@ msgstr "archivePath"
msgid "arduino-preprocessor pattern is missing"
msgstr "arduino-preprocessor pattern is missing"
#: commands/upload/upload.go:5
66
#: commands/upload/upload.go:5
53
msgid "autodetect build artifact: %s"
msgstr "autodetect build artifact: %s"
#: commands/upload/upload.go:5
51
#: commands/upload/upload.go:5
38
msgid "binary file not found in %s"
msgstr "binary file not found in %s"
...
...
@@ -2104,7 +2104,7 @@ msgstr "board not found"
msgid "boardname"
msgstr "boardname"
#: commands/upload/upload.go:4
65
#: commands/upload/upload.go:4
52
msgid "burn bootloader error: %s"
msgstr "burn bootloader error: %s"
...
...
@@ -2153,8 +2153,8 @@ msgstr "cannot create build cache directory: %s"
msgid "cannot create build directory: %s"
msgstr "cannot create build directory: %s"
#: commands/upload/upload.go:
508
#: commands/upload/upload.go:5
15
#: commands/upload/upload.go:
495
#: commands/upload/upload.go:5
02
msgid "cannot execute upload tool: %s"
msgstr "cannot execute upload tool: %s"
...
...
@@ -2162,7 +2162,7 @@ msgstr "cannot execute upload tool: %s"
msgid "cannot export sketch metadata: %s"
msgstr "cannot export sketch metadata: %s"
#: commands/upload/upload.go:
93
#: commands/upload/upload.go:
87
msgid "cannot find tool: undefined '%s' property"
msgstr "cannot find tool: undefined '%s' property"
...
...
@@ -2175,7 +2175,7 @@ msgstr "checking lib install prerequisites: %s"
msgid "checking local archive integrity"
msgstr "checking local archive integrity"
#: commands/upload/upload.go:4
62
#: commands/upload/upload.go:4
49
msgid "chip erase error: %s"
msgstr "chip erase error: %s"
...
...
@@ -2222,7 +2222,7 @@ msgid "communication out of sync, expected 'stop', received '%s'"
msgstr "communication out of sync, expected 'stop', received '%s'"
#: commands/debug/debug_info.go:123
#: commands/upload/upload.go:3
66
#: commands/upload/upload.go:3
53
msgid "compiled sketch not found in %s"
msgstr "compiled sketch not found in %s"
...
...
@@ -2239,7 +2239,7 @@ msgstr "converting library %[1]s to rpc struct: %[2]w"
msgid "copying output file %s"
msgstr "copying output file %s"
#: commands/upload/upload.go:6
23
#: commands/upload/upload.go:6
10
msgid "could not find a valid build artifact"
msgstr "could not find a valid build artifact"
...
...
@@ -2393,7 +2393,7 @@ msgid "error: %s and %s flags cannot be used together"
msgstr "error: %s and %s flags cannot be used together"
#: commands/debug/debug_info.go:126
#: commands/upload/upload.go:3
69
#: commands/upload/upload.go:3
56
msgid "expected compiled sketch in directory %s, but is a file instead"
msgstr "expected compiled sketch in directory %s, but is a file instead"
...
...
@@ -2516,8 +2516,8 @@ msgstr "importing sketch metadata: %s"
#: commands/compile/compile.go:115
#: commands/upload/programmers_list.go:37
#: commands/upload/programmers_list.go:43
#: commands/upload/upload.go:
208
#: commands/upload/upload.go:2
15
#: commands/upload/upload.go:
194
#: commands/upload/upload.go:2
01
msgid "incorrect FQBN: %s"
msgstr "incorrect FQBN: %s"
...
...
@@ -2549,7 +2549,7 @@ msgstr "invalid 'add' message: missing port"
msgid "invalid 'remove' message: missing port"
msgstr "invalid 'remove' message: missing port"
#: commands/upload/upload.go:2
68
#: commands/upload/upload.go:2
54
msgid "invalid 'upload.tool' property: %s"
msgstr "invalid 'upload.tool' property: %s"
...
...
@@ -2639,7 +2639,7 @@ msgstr "invalid hash '%[1]s': %[2]s"
#: commands/lib/list.go:41
#: commands/lib/list.go:46
#: commands/lib/search.go:35
#: commands/upload/upload.go:5
2
#: commands/upload/upload.go:5
1
msgid "invalid instance"
msgstr "invalid instance"
...
...
@@ -2684,7 +2684,7 @@ msgstr "invalid path writing inventory file: %[1]s error: %[2]w"
msgid "invalid platform archive size: %s"
msgstr "invalid platform archive size: %s"
#: commands/upload/upload.go:4
95
#: commands/upload/upload.go:4
82
msgid "invalid recipe '%[1]s': %[2]s"
msgstr "invalid recipe '%[1]s': %[2]s"
...
...
@@ -2755,7 +2755,7 @@ msgstr "loading %[1]s: %[2]s"
#: commands/board/details.go:44
#: commands/lib/list.go:60
#: commands/upload/upload.go:6
2
#: commands/upload/upload.go:6
1
msgid "loading board data: %s"
msgstr "loading board data: %s"
...
...
@@ -2828,7 +2828,7 @@ msgstr "missing platform %[1]s:%[2]s referenced by board %[3]s"
msgid "missing platform release %[1]s:%[2]s referenced by board %[3]s"
msgstr "missing platform release %[1]s:%[2]s referenced by board %[3]s"
#: commands/upload/upload.go:4
7
#: commands/upload/upload.go:4
6
msgid "missing protocol"
msgstr "missing protocol"
...
...
@@ -2842,7 +2842,7 @@ msgstr "missing sketchPath"
msgid "moving extracted archive to destination dir: %s"
msgstr "moving extracted archive to destination dir: %s"
#: commands/upload/upload.go:6
18
#: commands/upload/upload.go:6
05
msgid "multiple build artifacts found: '%[1]s' and '%[2]s'"
msgstr "multiple build artifacts found: '%[1]s' and '%[2]s'"
...
...
@@ -2856,7 +2856,7 @@ msgstr "no FQBN provided"
#: commands/debug/debug_info.go:61
#: commands/upload/programmers_list.go:33
#: commands/upload/upload.go:
204
#: commands/upload/upload.go:
190
msgid "no Fully Qualified Board Name provided"
msgstr "no Fully Qualified Board Name provided"
...
...
@@ -2872,11 +2872,11 @@ msgstr "no executable specified"
msgid "no instance specified"
msgstr "no instance specified"
#: commands/upload/upload.go:1
95
#: commands/upload/upload.go:1
81
msgid "no programmer specified for burning bootloader"
msgstr "no programmer specified for burning bootloader"
#: commands/upload/upload.go:5
73
#: commands/upload/upload.go:5
60
msgid "no sketch or build directory/file specified"
msgstr "no sketch or build directory/file specified"
...
...
@@ -2888,7 +2888,7 @@ msgstr "no supported board found at %s"
msgid "no unique root dir in archive, found '%[1]s' and '%[2]s'"
msgstr "no unique root dir in archive, found '%[1]s' and '%[2]s'"
#: commands/upload/upload.go:4
90
#: commands/upload/upload.go:4
77
msgid "no upload port provided"
msgstr "no upload port provided"
...
...
@@ -2923,7 +2923,7 @@ msgstr "opening sketch"
#: commands/board/attach.go:50
#: commands/compile/compile.go:103
#: commands/upload/upload.go:1
37
#: commands/upload/upload.go:1
23
msgid "opening sketch: %s"
msgstr "opening sketch: %s"
...
...
@@ -2945,10 +2945,6 @@ msgstr "package '%s' not found"
msgid "package not found"
msgstr "package not found"
#: commands/upload/upload.go:115
msgid "parsing %s, property is not a boolean"
msgstr "parsing %s, property is not a boolean"
#: arduino/cores/packagemanager/loader.go:227
msgid "parsing IDE bundled index: %s"
msgstr "parsing IDE bundled index: %s"
...
...
@@ -2957,7 +2953,7 @@ msgstr "parsing IDE bundled index: %s"
#: arduino/cores/packagemanager/package_manager.go:136
#: commands/board/details.go:38
#: commands/lib/list.go:56
#: commands/upload/upload.go:5
7
#: commands/upload/upload.go:5
6
msgid "parsing fqbn: %s"
msgstr "parsing fqbn: %s"
...
...
@@ -3027,7 +3023,7 @@ msgstr "port"
msgid "port not found: %[1]s %[2]s"
msgstr "port not found: %[1]s %[2]s"
#: commands/upload/upload.go:2
32
#: commands/upload/upload.go:2
18
msgid "programmer '%s' not available"
msgstr "programmer '%s' not available"
...
...
@@ -3035,11 +3031,11 @@ msgstr "programmer '%s' not available"
msgid "programmer '%s' not found"
msgstr "programmer '%s' not found"
#: commands/upload/upload.go:1
69
#: commands/upload/upload.go:1
55
msgid "programmer not specified"
msgstr "programmer not specified"
#: commands/upload/upload.go:4
69
#: commands/upload/upload.go:4
56
msgid "programming error: %s"
msgstr "programming error: %s"
...
...
@@ -3105,7 +3101,7 @@ msgstr "reading package root dir: %s"
msgid "reading sketch metadata %[1]s: %[2]s"
msgstr "reading sketch metadata %[1]s: %[2]s"
#: commands/upload/upload.go:4
84
#: commands/upload/upload.go:4
71
msgid "recipe not found '%s'"
msgstr "recipe not found '%s'"
...
...
@@ -3151,7 +3147,7 @@ msgstr "rescanning libraries: %s"
msgid "retrieving Arduino public keys: %s"
msgstr "retrieving Arduino public keys: %s"
#: commands/upload/upload.go:3
63
#: commands/upload/upload.go:3
50
msgid "retrieving build artifacts: %s"
msgstr "retrieving build artifacts: %s"
...
...
@@ -3378,8 +3374,8 @@ msgstr "upgrade everything to the latest version"
msgid "upgrading platform: %s"
msgstr "upgrading platform: %s"
#: commands/upload/upload.go:4
73
#: commands/upload/upload.go:5
19
#: commands/upload/upload.go:4
60
#: commands/upload/upload.go:5
06
msgid "uploading error: %s"
msgstr "uploading error: %s"
...
...
i18n/rice-box.go
View file @
f61c1bc3
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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