@@ -17,13 +17,13 @@ package config
17
17
18
18
import (
19
19
"os"
20
- "strings"
21
20
21
+ "github.com/arduino/arduino-cli/commands/daemon"
22
22
"github.com/arduino/arduino-cli/configuration"
23
23
"github.com/arduino/arduino-cli/internal/cli/feedback"
24
+ "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1"
24
25
"github.com/sirupsen/logrus"
25
26
"github.com/spf13/cobra"
26
- "github.com/spf13/viper"
27
27
)
28
28
29
29
func initDeleteCommand () * cobra.Command {
@@ -47,26 +47,9 @@ func runDeleteCommand(cmd *cobra.Command, args []string) {
47
47
logrus .Info ("Executing `arduino-cli config delete`" )
48
48
toDelete := args [0 ]
49
49
50
- keys := []string {}
51
- exists := false
52
- for _ , v := range configuration .Settings .AllKeys () {
53
- if ! strings .HasPrefix (v , toDelete ) {
54
- keys = append (keys , v )
55
- continue
56
- }
57
- exists = true
58
- }
59
-
60
- if ! exists {
61
- feedback .Fatal (tr ("Settings key doesn't exist" ), feedback .ErrGeneric )
62
- }
63
-
64
- updatedSettings := viper .New ()
65
- for _ , k := range keys {
66
- updatedSettings .Set (k , configuration .Settings .Get (k ))
67
- }
68
-
69
- if err := updatedSettings .WriteConfigAs (configuration .Settings .ConfigFileUsed ()); err != nil {
70
- feedback .Fatal (tr ("Can't write config file: %v" , err ), feedback .ErrGeneric )
50
+ svc := daemon.SettingsService {}
51
+ _ , err := svc .Delete (cmd .Context (), & settings.DeleteRequest {Key : toDelete , FilePath : configuration .Settings .ConfigFileUsed ()})
52
+ if err != nil {
53
+ feedback .Fatal (tr ("Error deleting the key %[1]s: %[2]v" , toDelete , err ), feedback .ErrGeneric )
71
54
}
72
55
}
0 commit comments