8000 Add Delete command to gRPC by MatteoPologruto · Pull Request #2212 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

Add Delete command to gRPC #2212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Delete command to settings
  • Loading branch information
MatteoPologruto committed Jun 27, 2023
commit 85956f033cc2a6467af19a021d1e5a379fb775e3
33 changes: 33 additions & 0 deletions commands/daemon/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,36 @@ func (s *SettingsService) Write(ctx context.Context, req *rpc.WriteRequest) (*rp
}
return &rpc.WriteResponse{}, nil
}

// Delete removes a key from the config file
func (s *SettingsService) Delete(ctx context.Context, req *rpc.DeleteRequest) (*rpc.DeleteResponse, error) {
toDelete := req.GetKey()

// Check if settings key actually existing, we don't use Viper.InConfig()
// since that doesn't check for keys formatted like daemon.port or those set
// with Viper.Set(). This way we check for all existing settings for sure.
keyExists := false
keys := []string{}
for _, k := range configuration.Settings.AllKeys() {
if !strings.HasPrefix(k, toDelete) {
keys = append(keys, k)
continue
}
keyExists = true
}

if !keyExists {
return nil, errors.New(tr("key not found in settings"))
}

// Override current settings to delete the key
updatedSettings := configuration.Init("")
for _, k := range keys {
updatedSettings.Set(k, configuration.Settings.Get(k))
}
configPath := configuration.Settings.ConfigFileUsed()
updatedSettings.SetConfigFile(configPath)
configuration.Settings = updatedSettings

return &rpc.DeleteResponse{}, nil
}
0