diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index 489c36d7edf..56bb6524edf 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -33,6 +33,7 @@ import ( "github.com/arduino/arduino-cli/metrics" srv_commands "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" srv_debug "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1" + srv_files "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/files/v1" srv_monitor "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/monitor/v1" srv_settings "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/settings/v1" "github.com/segmentio/stats/v4" @@ -98,6 +99,9 @@ func runDaemonCommand(cmd *cobra.Command, args []string) { // Register the debug session service srv_debug.RegisterDebugServiceServer(s, &daemon.DebugService{}) + // Register the files service + srv_files.RegisterFilesServiceServer(s, &daemon.FilesService{}) + if !daemonize { // When parent process ends terminate also the daemon go func() { diff --git a/commands/daemon/files.go b/commands/daemon/files.go new file mode 100644 index 00000000000..0fdfdb99655 --- /dev/null +++ b/commands/daemon/files.go @@ -0,0 +1,41 @@ +// This file is part of arduino-cli. +// +// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) +// +// This software is released under the GNU General Public License version 3, +// which covers the main part of arduino-cli. +// The terms of this license can be found at: +// https://www.gnu.org/licenses/gpl-3.0.en.html +// +// You can be released from the requirements of the above licenses by purchasing +// a commercial license. Buying such a license is mandatory if you want to +// modify or otherwise use the software for commercial activities involving the +// Arduino software without disclosing the source code of your own applications. +// To purchase a commercial license, send an email to license@arduino.cc. + +package daemon + +import ( + "context" + "os" + + rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/files/v1" +) + +// FilesService implements the `Files` service +type FilesService struct { + rpc.UnimplementedFilesServiceServer +} + +// LoadFile returns a requested file content or an error. +func (s *FilesService) LoadFile(ctx context.Context, req *rpc.LoadFileRequest) (*rpc.LoadFileResponse, error) { + content, err := os.ReadFile(req.Path) + if err == nil { + return &rpc.LoadFileResponse{ + Content: content, + Type: rpc.ContentType_CONTENT_TYPE_RAW_UNSPECIFIED, + }, nil + } + + return nil, err +}