Skip to content

Commit 6aa742f

Browse files
committed
Config set adds only unique values
1 parent 384c30c commit 6aa742f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

internal/algorithms/slices.go

+14
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,17 @@ func NotEquals[T comparable](value T) Matcher[T] {
7171
return x != value
7272
}
7373
}
74+
75+
// Uniq return a copy of the input array with all duplicates removed
76+
func Uniq[T comparable](in []T) []T {
77+
have := map[T]bool{}
78+
var out []T
79+
for _, v := range in {
80+
if have[v] {
81+
continue
82+
}
83+
out = append(out, v)
84+
have[v] = true
85+
}
86+
return out
87+
}

internal/cli/config/set.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"os"
2222

23+
f "github.com/arduino/arduino-cli/internal/algorithms"
2324
"github.com/arduino/arduino-cli/internal/cli/feedback"
2425
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2526
"github.com/sirupsen/logrus"
@@ -59,8 +60,8 @@ func runSetCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args [
5960
req.EncodedValue = args[1]
6061
req.ValueFormat = "cli"
6162
} else {
62-
// Array
63-
jsonValues, err := json.Marshal(args[1:])
63+
// Uniq Array
64+
jsonValues, err := json.Marshal(f.Uniq(args[1:]))
6465
if err != nil {
6566
feedback.Fatal(tr("Error setting value: %v", err), feedback.ErrGeneric)
6667
}

0 commit comments

Comments
 (0)