cmd.init   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
/*
2
 * Copyright (c) 2023 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 all
12
 * copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
 * OTHER DEALINGS IN THE SOFTWARE.
22
 */
23
24
package cmd
25
26
import (
27
	"fmt"
28
	"os"
29
	"wasabi-cleanup/internal/config"
30
31
	"github.com/spf13/cobra"
32
)
33
34
var cfgFile string
35
var Verbose bool
36
var Version bool
37
38
func SetVersionInfo(version, commit, date string) {
39
	rootCmd.Version = fmt.Sprintf("%s (Built on %s from Git SHA %s)", version, date, commit)
40
}
41
42
// rootCmd represents the base command when called without any subcommands
43
var rootCmd = &cobra.Command{
44
	Use:   "wasabi-cleanup",
45
	Short: "A tool to cleanup Wasabi bucket files that are out of compliance retention",
46
	Long: `wasabi-cleanup is a CLI library that allows you to cleanup files in your
47
Wasabi buckets that are out of the compliance retention date.`,
48
}
49
50
// Execute adds all child commands to the root command and sets flags appropriately.
51
// This is called by main.main(). It only needs to happen once to the rootCmd.
52
func Execute() {
53
	err := rootCmd.Execute()
54
	if err != nil {
55
		os.Exit(1)
56
	}
57
}
58
59
func init() {
60
	cobra.OnInitialize(initConfig)
61
62
	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.wasabi-cleanup/config)")
63
	rootCmd.PersistentFlags().BoolVarP(&Version, "version", "V", false, "Software Version")
64
	rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
65
66
	rootCmd.AddCommand(cleanCmd)
67
}
68
69
// initConfig reads in config file and ENV variables if set.
70
func initConfig() {
71
	config.InitConfig()
72
}
73