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
c355478f
Commit
c355478f
authored
May 06, 2024
by
Cristian Maglie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated client_example
parent
278a3314
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
90 deletions
+56
-90
commands/service_settings.go
commands/service_settings.go
+1
-1
rpc/internal/client_example/main.go
rpc/internal/client_example/main.go
+55
-89
No files found.
commands/service_settings.go
View file @
c355478f
...
...
@@ -177,7 +177,7 @@ func (s *arduinoCoreServerImpl) ConfigurationSave(ctx context.Context, req *rpc.
}
return
&
rpc
.
ConfigurationSaveResponse
{
EncodedSettings
:
string
(
data
)},
nil
case
"json"
:
data
,
err
:=
json
.
Marshal
(
s
.
settings
)
data
,
err
:=
json
.
Marshal
Indent
(
s
.
settings
,
""
,
" "
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error marshalling settings: %v"
,
err
)
}
...
...
rpc/internal/client_example/main.go
View file @
c355478f
...
...
@@ -23,6 +23,7 @@ import (
"io"
"log"
"os"
"path"
"path/filepath"
"strings"
"time"
...
...
@@ -71,40 +72,24 @@ func main() {
callLoadSketch
(
client
)
// Use SetValue to configure the arduino-cli directories.
log
.
Println
(
"calling SetValue"
)
callSetValue
(
client
)
callSetValue
(
client
,
"directories.data"
,
`"`
+
dataDir
+
`"`
)
callSetValue
(
client
,
"directories.downloads"
,
`"`
+
path
.
Join
(
dataDir
,
"staging"
)
+
`"`
)
callSetValue
(
client
,
"directories.user"
,
`"`
+
path
.
Join
(
dataDir
,
"sketchbook"
)
+
`"`
)
// List all settings
log
.
Println
(
"calling SettingsGetAll()"
)
callGetAll
(
client
)
callConfigurationSave
(
client
)
// Merge applies multiple settings values at once.
log
.
Println
(
"calling SettingsMerge()"
)
call
Merge
(
client
,
`{"foo": {"value": "bar"}, "daemon":{"port":"422"}, "board_manager": {"additional_urls":["https://example.com"]}}
`
)
callSetValue
(
client
,
"daemon.port"
,
`"422"`
)
call
SetValue
(
client
,
"board_manager.additional_urls"
,
`[ "https://example.com" ]
`
)
log
.
Println
(
"calling SettingsGetAll()"
)
callGetAll
(
client
)
callConfigurationSave
(
client
)
log
.
Println
(
"calling SettingsMerge()"
)
callMerge
(
client
,
`{"foo": {} }`
)
callSetValue
(
client
,
"daemon.port"
,
""
)
callGetValue
(
client
,
"daemon.port"
)
callGetValue
(
client
,
"directories.data"
)
log
.
Println
(
"calling SettingsGetAll()"
)
callGetAll
(
client
)
log
.
Println
(
"calling SettingsMerge()"
)
callMerge
(
client
,
`{"foo": "bar" }`
)
// Get the value of the foo key.
log
.
Println
(
"calling SettingsGetValue(foo)"
)
callGetValue
(
client
)
// List all settings
log
.
Println
(
"calling SettingsGetAll()"
)
callGetAll
(
client
)
// Write settings to file.
log
.
Println
(
"calling Write()"
)
callWrite
(
client
)
callConfigurationSave
(
client
)
// Before we can do anything with the CLI, an "instance" must be created.
// We keep a reference to the created instance because we will need it to
...
...
@@ -243,85 +228,66 @@ func callVersion(client rpc.ArduinoCoreServiceClient) {
log
.
Printf
(
"arduino-cli version: %v"
,
versionResp
.
GetVersion
())
}
func
callSetValue
(
client
rpc
.
ArduinoCoreServiceClient
)
{
// _, err := client.SettingsSetValue(context.Background(),
// &rpc.SettingsSetValueRequest{
// Key: "directories",
// JsonData: `{"data": "` + dataDir + `", "downloads": "` + path.Join(dataDir, "staging") + `", "user": "` + path.Join(dataDir, "sketchbook") + `"}`,
// })
func
callSetValue
(
client
rpc
.
ArduinoCoreServiceClient
,
key
,
jsonValue
string
)
{
log
.
Printf
(
"Calling SetValue: %s = %s"
,
key
,
jsonValue
)
_
,
err
:=
client
.
SettingsSetValue
(
context
.
Background
(),
&
rpc
.
SettingsSetValueRequest
{
Key
:
key
,
EncodedValue
:
jsonValue
,
})
//
if err != nil {
//
log.Fatalf("Error setting settings value: %s", err)
//
}
if
err
!=
nil
{
log
.
Fatalf
(
"Error setting settings value: %s"
,
err
)
}
}
func
callSetProxy
(
client
rpc
.
ArduinoCoreServiceClient
)
{
//
_, err := client.SettingsSetValue(context.Background(),
//
&rpc.SettingsSetValueRequest{
// Key:
"network.proxy",
// JsonData
: `"http://localhost:3128"`,
//
})
_
,
err
:=
client
.
SettingsSetValue
(
context
.
Background
(),
&
rpc
.
SettingsSetValueRequest
{
Key
:
"network.proxy"
,
EncodedValue
:
`"http://localhost:3128"`
,
})
//
if err != nil {
//
log.Fatalf("Error setting settings value: %s", err)
//
}
if
err
!=
nil
{
log
.
Fatalf
(
"Error setting settings value: %s"
,
err
)
}
}
func
callUnsetProxy
(
client
rpc
.
ArduinoCoreServiceClient
)
{
// _, err := client.SettingsSetValue(context.Background(),
// &rpc.SettingsSetValueRequest{
// Key: "network.proxy",
// JsonData: `""`,
// })
// if err != nil {
// log.Fatalf("Error setting settings value: %s", err)
// }
}
func
callMerge
(
client
rpc
.
ArduinoCoreServiceClient
,
jsonData
string
)
{
// _, err := client.SettingsMerge(context.Background(),
// &rpc.SettingsMergeRequest{
// JsonData: jsonData,
// })
_
,
err
:=
client
.
SettingsSetValue
(
context
.
Background
(),
&
rpc
.
SettingsSetValueRequest
{
Key
:
"network.proxy"
,
})
//
if err != nil {
// log.Fatalf("Error merging settings
: %s", err)
//
}
if
err
!=
nil
{
log
.
Fatalf
(
"Error setting settings value
: %s"
,
err
)
}
}
func
callGetValue
(
client
rpc
.
ArduinoCoreServiceClient
)
{
//
getValueResp, err := client.SettingsGetValue(context.Background(),
//
&rpc.SettingsGetValueRequest{
// Key: "foo"
,
//
})
func
callGetValue
(
client
rpc
.
ArduinoCoreServiceClient
,
key
string
)
{
getValueResp
,
err
:=
client
.
SettingsGetValue
(
context
.
Background
(),
&
rpc
.
SettingsGetValueRequest
{
Key
:
key
,
})
//
if err != nil {
//
log.Fatalf("Error getting settings value: %s", err)
//
}
if
err
!=
nil
{
log
.
Fatalf
(
"Error getting settings value: %s"
,
err
)
}
// log.Printf("Value: %s: %s", getValueResp.GetKey(), getValueResp.GetJsonData
())
log
.
Printf
(
"%s = %s"
,
key
,
getValueResp
.
GetEncodedValue
())
}
func
callGetAll
(
client
rpc
.
ArduinoCoreServiceClient
)
{
// getAllResp, err := client.SettingsGetAll(context.Background(), &rpc.SettingsGetAllRequest{})
// if err != nil {
// log.Fatalf("Error getting settings: %s", err)
// }
// log.Printf("Settings: %s", getAllResp.GetJsonData())
}
func
callConfigurationSave
(
client
rpc
.
ArduinoCoreServiceClient
)
{
log
.
Println
(
"calling ConfigurationSave() >>"
)
getAllResp
,
err
:=
client
.
ConfigurationSave
(
context
.
Background
(),
&
rpc
.
ConfigurationSaveRequest
{
SettingsFormat
:
"json"
,
})
func
callWrite
(
client
rpc
.
ArduinoCoreServiceClient
)
{
// _, err := client.SettingsWrite(context.Background(),
// &rpc.SettingsWriteRequest{
// FilePath: path.Join(dataDir, "written-rpc.Settingsyml"),
// })
if
err
!=
nil
{
log
.
Fatalf
(
"Error getting settings: %s"
,
err
)
}
// if err != nil {
// log.Fatalf("Error writing settings: %s", err)
// }
log
.
Printf
(
"Settings follow:
\n\n
%s"
,
getAllResp
.
GetEncodedSettings
())
}
func
createInstance
(
client
rpc
.
ArduinoCoreServiceClient
)
*
rpc
.
Instance
{
...
...
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