1
|
|
|
/* |
2
|
|
|
Copyright © 2022 Clive Walkden <[email protected]> |
3
|
|
|
|
4
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
5
|
|
|
of this software and associated documentation files (the "Software"), to deal |
6
|
|
|
in the Software without restriction, including without limitation the rights |
7
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
8
|
|
|
copies of the Software, and to permit persons to whom the Software is |
9
|
|
|
furnished to do so, subject to the following conditions: |
10
|
|
|
|
11
|
|
|
The above copyright notice and this permission notice shall be included in |
12
|
|
|
all copies or substantial portions of the Software. |
13
|
|
|
|
14
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
20
|
|
|
THE SOFTWARE. |
21
|
|
|
*/ |
22
|
|
|
package cmd |
23
|
|
|
|
24
|
|
|
import ( |
25
|
|
|
"os" |
26
|
|
|
"wasabiCleanup/internal/config" |
27
|
|
|
|
28
|
|
|
"github.com/spf13/cobra" |
29
|
|
|
) |
30
|
|
|
|
31
|
|
|
var cfgFile string |
32
|
|
|
var Verbose bool |
33
|
|
|
var Version bool |
34
|
|
|
|
35
|
|
|
// rootCmd represents the base command when called without any subcommands |
36
|
|
|
var rootCmd = &cobra.Command{ |
37
|
|
|
Use: "wasabiCleanup", |
38
|
|
|
Short: "A tool to cleanup Wasabi bucket files that are out of compliance retention", |
39
|
|
|
Long: `wasabiCleanup is a CLI library that allows you to cleanup files in your |
40
|
|
|
Wasabi buckets that are out of the compliance retention date.`, |
41
|
|
|
Version: "1.1.0", |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// Execute adds all child commands to the root command and sets flags appropriately. |
45
|
|
|
// This is called by main.main(). It only needs to happen once to the rootCmd. |
46
|
|
|
func Execute() { |
47
|
|
|
err := rootCmd.Execute() |
48
|
|
|
if err != nil { |
49
|
|
|
os.Exit(1) |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
func init() { |
54
|
|
|
cobra.OnInitialize(initConfig) |
55
|
|
|
|
56
|
|
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.wasabiCleanup/config)") |
57
|
|
|
rootCmd.PersistentFlags().BoolVarP(&Version, "version", "V", false, "Software Version") |
58
|
|
|
rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output") |
59
|
|
|
|
60
|
|
|
rootCmd.AddCommand(cleanCmd) |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// initConfig reads in config file and ENV variables if set. |
64
|
|
|
func initConfig() { |
65
|
|
|
config.InitConfig() |
66
|
|
|
} |
67
|
|
|
|