Skip to content

Commit 8d3dafa

Browse files
committed
Inlining methods in ArduinoCoreServiceImpl (part 16: CleanDownloadCacheDirectory, CheckForArduinoCLIUpdates)
1 parent 956148c commit 8d3dafa

File tree

7 files changed

+23
-33
lines changed

7 files changed

+23
-33
lines changed

Diff for: commands/service.go

-12
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package commands
1818
import (
1919
"context"
2020

21-
"github.com/arduino/arduino-cli/commands/cache"
22-
"github.com/arduino/arduino-cli/commands/updatecheck"
2321
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2422
)
2523

@@ -41,13 +39,3 @@ type arduinoCoreServerImpl struct {
4139
func (s *arduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionRequest) (*rpc.VersionResponse, error) {
4240
return &rpc.VersionResponse{Version: s.versionString}, nil
4341
}
44-
45-
// CheckForArduinoCLIUpdates FIXMEDOC
46-
func (s *arduinoCoreServerImpl) CheckForArduinoCLIUpdates(ctx context.Context, req *rpc.CheckForArduinoCLIUpdatesRequest) (*rpc.CheckForArduinoCLIUpdatesResponse, error) {
47-
return updatecheck.CheckForArduinoCLIUpdates(ctx, req)
48-
}
49-
50-
// CleanDownloadCacheDirectory FIXMEDOC
51-
func (s *arduinoCoreServerImpl) CleanDownloadCacheDirectory(ctx context.Context, req *rpc.CleanDownloadCacheDirectoryRequest) (*rpc.CleanDownloadCacheDirectoryResponse, error) {
52-
return cache.CleanDownloadCacheDirectory(ctx, req)
53-
}

Diff for: commands/cache/clean.go renamed to commands/service_cache_clean.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of arduino-cli.
22
//
3-
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
44
//
55
// This software is released under the GNU General Public License version 3,
66
// which covers the main part of arduino-cli.
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package cache
16+
package commands
1717

1818
import (
1919
"context"
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
// CleanDownloadCacheDirectory clean the download cache directory (where archives are downloaded).
26-
func CleanDownloadCacheDirectory(ctx context.Context, req *rpc.CleanDownloadCacheDirectoryRequest) (*rpc.CleanDownloadCacheDirectoryResponse, error) {
26+
func (s *arduinoCoreServerImpl) CleanDownloadCacheDirectory(ctx context.Context, req *rpc.CleanDownloadCacheDirectoryRequest) (*rpc.CleanDownloadCacheDirectoryResponse, error) {
2727
cachePath := configuration.DownloadsDir(configuration.Settings)
2828
err := cachePath.RemoveAll()
2929
if err != nil {

Diff for: commands/updatecheck/check_for_updates.go renamed to commands/service_check_for_updates.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package updatecheck
16+
package commands
1717

1818
import (
1919
"context"
@@ -29,7 +29,7 @@ import (
2929
semver "go.bug.st/relaxed-semver"
3030
)
3131

32-
func CheckForArduinoCLIUpdates(ctx context.Context, req *rpc.CheckForArduinoCLIUpdatesRequest) (*rpc.CheckForArduinoCLIUpdatesResponse, error) {
32+
func (s *arduinoCoreServerImpl) CheckForArduinoCLIUpdates(ctx context.Context, req *rpc.CheckForArduinoCLIUpdatesRequest) (*rpc.CheckForArduinoCLIUpdatesResponse, error) {
3333
currentVersion, err := semver.Parse(version.VersionInfo.VersionString)
3434
if err != nil {
3535
return nil, err

Diff for: internal/cli/cache/cache.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ import (
1919
"os"
2020

2121
"github.com/arduino/arduino-cli/internal/i18n"
22+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2223
"github.com/spf13/cobra"
2324
)
2425

2526
var tr = i18n.Tr
2627

2728
// NewCommand created a new `cache` command
28-
func NewCommand() *cobra.Command {
29+
func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
2930
cacheCommand := &cobra.Command{
3031
Use: "cache",
3132
Short: tr("Arduino cache commands."),
@@ -34,7 +35,7 @@ func NewCommand() *cobra.Command {
3435
" " + os.Args[0] + " cache clean\n\n",
3536
}
3637

37-
cacheCommand.AddCommand(initCleanCommand())
38+
cacheCommand.AddCommand(initCleanCommand(srv))
3839

3940
return cacheCommand
4041
}

Diff for: internal/cli/cache/clean.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,30 @@ import (
1919
"context"
2020
"os"
2121

22-
"github.com/arduino/arduino-cli/commands/cache"
2322
"github.com/arduino/arduino-cli/internal/cli/feedback"
2423
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2524
"github.com/sirupsen/logrus"
2625
"github.com/spf13/cobra"
2726
)
2827

29-
func initCleanCommand() *cobra.Command {
28+
func initCleanCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
3029
cleanCommand := &cobra.Command{
3130
Use: "clean",
3231
Short: tr("Delete Boards/Library Manager download cache."),
3332
Long: tr("Delete contents of the `directories.downloads` folder, where archive files are staged during installation of libraries and boards platforms."),
3433
Example: " " + os.Args[0] + " cache clean",
3534
Args: cobra.NoArgs,
36-
Run: runCleanCommand,
35+
Run: func(cmd *cobra.Command, args []string) {
36+
runCleanCommand(srv)
37+
},
3738
}
3839
return cleanCommand
3940
}
4041

41-
func runCleanCommand(cmd *cobra.Command, args []string) {
42+
func runCleanCommand(srv rpc.ArduinoCoreServiceServer) {
4243
logrus.Info("Executing `arduino-cli cache clean`")
4344

44-
_, err := cache.CleanDownloadCacheDirectory(context.Background(), &rpc.CleanDownloadCacheDirectoryRequest{})
45+
_, err := srv.CleanDownloadCacheDirectory(context.Background(), &rpc.CleanDownloadCacheDirectoryRequest{})
4546
if err != nil {
4647
feedback.Fatal(tr("Error cleaning caches: %v", err), feedback.ErrGeneric)
4748
}

Diff for: internal/cli/cli.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"os"
2323
"strings"
2424

25-
"github.com/arduino/arduino-cli/commands/updatecheck"
2625
"github.com/arduino/arduino-cli/internal/cli/board"
2726
"github.com/arduino/arduino-cli/internal/cli/burnbootloader"
2827
"github.com/arduino/arduino-cli/internal/cli/cache"
@@ -80,7 +79,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
8079
if cmd.Name() != "version" {
8180
updaterMessageChan = make(chan *semver.Version)
8281
go func() {
83-
res, err := updatecheck.CheckForArduinoCLIUpdates(context.Background(), &rpc.CheckForArduinoCLIUpdatesRequest{})
82+
res, err := srv.CheckForArduinoCLIUpdates(context.Background(), &rpc.CheckForArduinoCLIUpdatesRequest{})
8483
if err != nil {
8584
logrus.Warnf("Error checking for updates: %v", err)
8685
updaterMessageChan <- nil
@@ -110,7 +109,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
110109
cmd.SetUsageTemplate(getUsageTemplate())
111110

112111
cmd.AddCommand(board.NewCommand(srv))
113-
cmd.AddCommand(cache.NewCommand())
112+
cmd.AddCommand(cache.NewCommand(srv))
114113
cmd.AddCommand(compile.NewCommand(srv))
115114
cmd.AddCommand(completion.NewCommand())
116115
cmd.AddCommand(config.NewCommand())
@@ -126,7 +125,7 @@ func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
126125
cmd.AddCommand(upload.NewCommand(srv))
127126
cmd.AddCommand(debug.NewCommand(srv))
128127
cmd.AddCommand(burnbootloader.NewCommand(srv))
129-
cmd.AddCommand(version.NewCommand())
128+
cmd.AddCommand(version.NewCommand(srv))
130129
cmd.AddCommand(feedback.NewCommand())
131130
cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, tr("Print the logs on the standard output."))
132131
cmd.Flag("verbose").Hidden = true

Diff for: internal/cli/version/version.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"os"
2121
"strings"
2222

23-
"github.com/arduino/arduino-cli/commands/updatecheck"
2423
"github.com/arduino/arduino-cli/internal/cli/feedback"
2524
"github.com/arduino/arduino-cli/internal/cli/updater"
2625
"github.com/arduino/arduino-cli/internal/i18n"
@@ -33,19 +32,21 @@ import (
3332
var tr = i18n.Tr
3433

3534
// NewCommand created a new `version` command
36-
func NewCommand() *cobra.Command {
35+
func NewCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
3736
versionCommand := &cobra.Command{
3837
Use: "version",
3938
Short: tr("Shows version number of Arduino CLI."),
4039
Long: tr("Shows the version number of Arduino CLI which is installed on your system."),
4140
Example: " " + os.Args[0] + " version",
4241
Args: cobra.NoArgs,
43-
Run: runVersionCommand,
42+
Run: func(cmd *cobra.Command, args []string) {
43+
runVersionCommand(srv)
44+
},
4445
}
4546
return versionCommand
4647
}
4748

48-
func runVersionCommand(cmd *cobra.Command, args []string) {
49+
func runVersionCommand(srv rpc.ArduinoCoreServiceServer) {
4950
logrus.Info("Executing `arduino-cli version`")
5051

5152
info := version.VersionInfo
@@ -57,7 +58,7 @@ func runVersionCommand(cmd *cobra.Command, args []string) {
5758
}
5859

5960
latestVersion := ""
60-
res, err := updatecheck.CheckForArduinoCLIUpdates(context.Background(), &rpc.CheckForArduinoCLIUpdatesRequest{})
61+
res, err := srv.CheckForArduinoCLIUpdates(context.Background(), &rpc.CheckForArduinoCLIUpdatesRequest{})
6162
if err != nil {
6263
feedback.Warning("Failed to check for updates: " + err.Error())
6364
} else {

0 commit comments

Comments
 (0)