Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable root-level help message #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ tink-server
**/tink-worker
bin/
certs/

/tink
1 change: 1 addition & 0 deletions cli/tink/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/tink
20 changes: 12 additions & 8 deletions cli/tink/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 10 additions & 2 deletions cli/tink/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}