Commit 6aa742ff authored by Cristian Maglie's avatar Cristian Maglie

Config set adds only unique values

parent 384c30c8
......@@ -71,3 +71,17 @@ func NotEquals[T comparable](value T) Matcher[T] {
return x != value
}
}
// Uniq return a copy of the input array with all duplicates removed
func Uniq[T comparable](in []T) []T {
have := map[T]bool{}
var out []T
for _, v := range in {
if have[v] {
continue
}
out = append(out, v)
have[v] = true
}
return out
}
......@@ -20,6 +20,7 @@ import (
"encoding/json"
"os"
f "github.com/arduino/arduino-cli/internal/algorithms"
"github.com/arduino/arduino-cli/internal/cli/feedback"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/sirupsen/logrus"
......@@ -59,8 +60,8 @@ func runSetCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args [
req.EncodedValue = args[1]
req.ValueFormat = "cli"
} else {
// Array
jsonValues, err := json.Marshal(args[1:])
// Uniq Array
jsonValues, err := json.Marshal(f.Uniq(args[1:]))
if err != nil {
feedback.Fatal(tr("Error setting value: %v", err), feedback.ErrGeneric)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment