package cmd import ( "fmt" "os" "github.com/spf13/cobra" "github.com/spf13/viper" ) var ( action string cfgFile string verbose bool inputFile string showVersion bool ) // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "gitea-resource", Short: "Do things with Gitea from Concourse", } // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Println(err) os.Exit(1) } } func init() { cobra.OnInitialize(initConfig) rootCmd.PersistentFlags().StringVarP(&action, "action", "a", "check", "Concourse resource action to perform. May be check, in, or out.") rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Prints out debug messages.") rootCmd.PersistentFlags().BoolVarP(&showVersion, "version", "V", false, "Prints the version and exit.") rootCmd.PersistentFlags().StringVarP(&inputFile, "file", "F", "", "Consume input from file instead of stdin") } // initConfig reads in config file and ENV variables if set. func initConfig() { viper.AutomaticEnv() // read in environment variables that match }