diff --git a/.gitignore b/.gitignore index b5f7c3565..e5c91ae82 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ tink-server **/tink-worker bin/ certs/ - +/tink diff --git a/cli/tink/.gitignore b/cli/tink/.gitignore new file mode 100644 index 000000000..aaa6c93ce --- /dev/null +++ b/cli/tink/.gitignore @@ -0,0 +1 @@ +/tink diff --git a/cli/tink/cmd/root.go b/cli/tink/cmd/root.go index e61c35879..87370d15a 100644 --- a/cli/tink/cmd/root.go +++ b/cli/tink/cmd/root.go @@ -17,19 +17,23 @@ var rootCmd = &cobra.Command{ Short: "tinkerbell CLI", } +func init() { + cobra.OnInitialize(initConfig) + rootCmd.PersistentFlags().StringVarP(&cfgFile, "facility", "f", "", "used to build grcp and http urls") +} + // 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 Execute() error { + if !isHelpCommand() { + client.Setup() } + + return rootCmd.Execute() } -func init() { - cobra.OnInitialize(initConfig) - rootCmd.PersistentFlags().StringVarP(&cfgFile, "facility", "f", "", "used to build grcp and http urls") - client.Setup() +func isHelpCommand() bool { + return len(os.Args) == 1 || (len(os.Args) == 2 && os.Args[1] == "--help") } // initConfig reads in config file and ENV variables if set. diff --git a/cli/tink/main.go b/cli/tink/main.go index 995da0939..21b62633f 100644 --- a/cli/tink/main.go +++ b/cli/tink/main.go @@ -1,7 +1,15 @@ package main -import "github.com/tinkerbell/tink/cli/tink/cmd" +import ( + "fmt" + "os" + + "github.com/tinkerbell/tink/cli/tink/cmd" +) func main() { - cmd.Execute() + if err := cmd.Execute(); err != nil { + fmt.Fprintf(os.Stderr, fmt.Sprintf("%s", err.Error())) + os.Exit(1) + } }