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
Expand all
Hide 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
This diff is collapsed.
Click to expand it.
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