Passed
Push — main ( 1671e0...fc711e )
by Clive
02:41 queued 01:09
created

cmd.initConfig   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 0
dl 0
loc 2
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
	"os"
28
	"wasabiCleanup/internal/config"
29
30
	"github.com/spf13/cobra"
31
)
32
33
var cfgFile string
34
var Verbose bool
35
var Version bool
36
37
// rootCmd represents the base command when called without any subcommands
38
var rootCmd = &cobra.Command{
39
	Use:   "wasabiCleanup",
40
	Short: "A tool to cleanup Wasabi bucket files that are out of compliance retention",
41
	Long: `wasabiCleanup is a CLI library that allows you to cleanup files in your
42
Wasabi buckets that are out of the compliance retention date.`,
43
	Version: "1.1.0",
44
}
45
46
// Execute adds all child commands to the root command and sets flags appropriately.
47
// This is called by main.main(). It only needs to happen once to the rootCmd.
48
func Execute() {
49
	err := rootCmd.Execute()
50
	if err != nil {
51
		os.Exit(1)
52
	}
53
}
54
55
func init() {
56
	cobra.OnInitialize(initConfig)
57
58
	rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.wasabiCleanup/config)")
59
	rootCmd.PersistentFlags().BoolVarP(&Version, "version", "V", false, "Software Version")
60
	rootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
61
62
	rootCmd.AddCommand(cleanCmd)
63
}
64
65
// initConfig reads in config file and ENV variables if set.
66
func initConfig() {
67
	config.InitConfig()
68
}
69