|
| 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 | +} |
0 commit comments