Skip to content

Commit 8b3a9b8

Browse files
Massimiliano Pippimasci
Massimiliano Pippi
authored andcommitted
Merge branch 'cache_clean' of https://github.com/HowJMay/arduino-cli into HowJMay-cache_clean
2 parents afdf259 + d99c7c4 commit 8b3a9b8

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

Diff for: cli/cache/cache.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package cache
17+
18+
import (
19+
"os"
20+
21+
"github.com/spf13/cobra"
22+
)
23+
24+
// NewCommand created a new `cache` command
25+
func NewCommand() *cobra.Command {
26+
cacheCommand := &cobra.Command{
27+
Use: "cache",
28+
Short: "Arduino cache commands.",
29+
Long: "Arduino cache commands.",
30+
Example: "# Clean caches.\n" +
31+
" " + os.Args[0] + " cache clean\n\n",
32+
}
33+
34+
cacheCommand.AddCommand(initCleanCommand())
35+
36+
return cacheCommand
37+
}

Diff for: cli/cache/clean.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package cache
17+
18+
import (
19+
"os"
20+
21+
"github.com/arduino/arduino-cli/cli/errorcodes"
22+
"github.com/arduino/arduino-cli/cli/feedback"
23+
"github.com/sirupsen/logrus"
24+
"github.com/spf13/cobra"
25+
"github.com/spf13/viper"
26+
)
27+
28+
func initCleanCommand() *cobra.Command {
29+
cleanCommand := &cobra.Command{
30+
Use: "clean",
31+
Short: "Clean arduino cache.",
32+
Long: "Clean the files i.e. `~/arduino15/staging` in Linux.",
33+
Example: " " + os.Args[0] + " cache clean",
34+
Args: cobra.NoArgs,
35+
Run: runCleanCommand,
36+
}
37+
return cleanCommand
38+
}
39+
40+
func runCleanCommand(cmd *cobra.Command, args []string) {
41+
logrus.Info("Executing `arduino cache clean`")
42+
43+
cachePath := viper.GetString("directories.Downloads")
44+
err := os.RemoveAll(cachePath)
45+
if err != nil {
46+
feedback.Errorf("Error cleaning caches: %v", err)
47+
os.Exit(errorcodes.ErrGeneric)
48+
}
49+
}

Diff for: cli/cli.go

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424

2525
"github.com/arduino/arduino-cli/cli/board"
26+
"github.com/arduino/arduino-cli/cli/cache"
2627
"github.com/arduino/arduino-cli/cli/compile"
2728
"github.com/arduino/arduino-cli/cli/config"
2829
"github.com/arduino/arduino-cli/cli/core"
@@ -67,6 +68,7 @@ func init() {
6768
// this is here only for testing
6869
func createCliCommandTree(cmd *cobra.Command) {
6970
cmd.AddCommand(board.NewCommand())
71+
cmd.AddCommand(cache.NewCommand())
7072
cmd.AddCommand(compile.NewCommand())
7173
cmd.AddCommand(config.NewCommand())
7274
cmd.AddCommand(core.NewCommand())

Diff for: test/test_cache.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This file is part of arduino-cli.
2+
#
3+
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
#
5+
# This software is released under the GNU General Public License version 3,
6+
# which covers the main part of arduino-cli.
7+
# The terms of this license can be found at:
8+
# https://www.gnu.org/licenses/gpl-3.0.en.html
9+
#
10+
# You can be released from the requirements of the above licenses by purchasing
11+
# a commercial license. Buying such a license is mandatory if you want to modify or
12+
# otherwise use the software for commercial activities involving the Arduino
13+
# software without disclosing the source code of your own applications. To purchase
14+
# a commercial license, send an email to [email protected].
15+
import os
16+
import platform
17+
18+
19+
def test_cache_clean(run_command):
20+
"""
21+
Clean the cache under arduino caching file directory which is
22+
"<Arduino configure file path>/staging"
23+
"""
24+
result = run_command("cache clean")
25+
assert result.ok
26+
27+
# Generate /staging directory
28+
result = run_command("lib list")
29+
assert result.ok
30+
31+
result = run_command("cache clean")
32+
assert result.ok
33+
34+
running_platform = platform.system()
35+
homeDir = os.path.expanduser("~")
36+
if running_platform == "Linux":
37+
assert not (os.path.isdir(homeDir + ".arduino15/staging"))
38+
elif running_platform == "Darwin":
39+
assert not (os.path.isdir(homeDir + "Library/Arduino15/staging"))
40+
elif running_platform == "Windows":
41+
assert not (os.path.isdir(homeDir + "Arduino15/staging"))

0 commit comments

Comments
 (0)