@@ -95,16 +95,31 @@ func (s *arduinoCoreServerImpl) SettingsSetValue(ctx context.Context, req *rpc.S
95
95
key := req .GetKey ()
96
96
97
97
// Extract the value from the request
98
- jsonValue := []byte (req .GetValueJson ())
99
- if len (jsonValue ) == 0 {
98
+ encodedValue := []byte (req .GetEncodedValue ())
99
+ if len (encodedValue ) == 0 {
100
100
// If the value is empty, unset the key
101
101
s .settings .Delete (key )
102
102
return & rpc.SettingsSetValueResponse {}, nil
103
103
}
104
104
105
105
var newValue any
106
- if err := json .Unmarshal (jsonValue , & newValue ); err != nil {
107
- return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("invalid value: %v" , err )}
106
+ switch req .GetValueFormat () {
107
+ case "" , "json" :
108
+ if err := json .Unmarshal (encodedValue , & newValue ); err != nil {
109
+ return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("invalid value: %v" , err )}
110
+ }
111
+ case "yaml" :
112
+ if err := yaml .Unmarshal (encodedValue , & newValue ); err != nil {
113
+ return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("invalid value: %v" , err )}
114
+ }
115
+ case "cli" :
116
+ err := s .settings .SetFromCLIArgs (key , req .GetEncodedValue ())
117
+ if err != nil {
118
+ return nil , err
119
+ }
120
+ return & rpc.SettingsSetValueResponse {}, nil
121
+ default :
122
+ return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("unsupported value format: %s" , req .ValueFormat )}
108
123
}
109
124
110
125
// If the value is "null", unset the key
@@ -130,18 +145,28 @@ func (s *arduinoCoreServerImpl) SettingsGetValue(ctx context.Context, req *rpc.S
130
145
if ! ok {
131
146
return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("key %s not found" , key )}
132
147
}
133
- valueJson , err := json .Marshal (value )
134
- if err != nil {
135
- return nil , fmt .Errorf ("error marshalling value: %v" , err )
148
+
149
+ switch req .ValueFormat {
150
+ case "json" :
151
+ valueJson , err := json .Marshal (value )
152
+ if err != nil {
153
+ return nil , fmt .Errorf ("error marshalling value: %v" , err )
154
+ }
155
+ return & rpc.SettingsGetValueResponse {EncodedValue : string (valueJson )}, nil
156
+ case "yaml" :
157
+ valueYaml , err := yaml .Marshal (value )
158
+ if err != nil {
159
+ return nil , fmt .Errorf ("error marshalling value: %v" , err )
160
+ }
161
+ return & rpc.SettingsGetValueResponse {EncodedValue : string (valueYaml )}, nil
162
+ default :
163
+ return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("unsupported value format: %s" , req .ValueFormat )}
136
164
}
137
- return & rpc.SettingsGetValueResponse {
138
- ValueJson : string (valueJson ),
139
- }, nil
140
165
}
141
166
142
167
// ConfigurationSave encodes the current configuration in the specified format
143
168
func (s * arduinoCoreServerImpl ) ConfigurationSave (ctx context.Context , req * rpc.ConfigurationSaveRequest ) (* rpc.ConfigurationSaveResponse , error ) {
144
- switch req .GetFormat () {
169
+ switch req .GetSettingsFormat () {
145
170
case "yaml" :
146
171
data , err := yaml .Marshal (s .settings )
147
172
if err != nil {
@@ -155,13 +180,13 @@ func (s *arduinoCoreServerImpl) ConfigurationSave(ctx context.Context, req *rpc.
155
180
}
156
181
return & rpc.ConfigurationSaveResponse {EncodedSettings : string (data )}, nil
157
182
default :
158
- return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("unsupported format: %s" , req .GetFormat ())}
183
+ return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("unsupported format: %s" , req .GetSettingsFormat ())}
159
184
}
160
185
}
161
186
162
187
// SettingsReadFromFile read settings from a YAML file and replace the settings currently stored in memory.
163
188
func (s * arduinoCoreServerImpl ) ConfigurationOpen (ctx context.Context , req * rpc.ConfigurationOpenRequest ) (* rpc.ConfigurationOpenResponse , error ) {
164
- switch req .GetFormat () {
189
+ switch req .GetSettingsFormat () {
165
190
case "yaml" :
166
191
err := yaml .Unmarshal ([]byte (req .GetEncodedSettings ()), s .settings )
167
192
if err != nil {
@@ -175,7 +200,7 @@ func (s *arduinoCoreServerImpl) ConfigurationOpen(ctx context.Context, req *rpc.
175
200
}
176
201
return & rpc.ConfigurationOpenResponse {}, nil
177
202
default :
178
- return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("unsupported format: %s" , req .GetFormat ())}
203
+ return nil , & cmderrors.InvalidArgumentError {Message : fmt .Sprintf ("unsupported format: %s" , req .GetSettingsFormat ())}
179
204
}
180
205
}
181
206
0 commit comments