Skip to content
Merged
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
18 changes: 14 additions & 4 deletions cmd/shp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
goflag "flag"
"fmt"
"io"
"os"

"github.com/spf13/pflag"
Expand Down Expand Up @@ -35,14 +36,19 @@ var hiddenLogFlags = []string{
}

func main() {
streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
rootCmd := cmd.NewCmdSHP(&streams)

if err := initGoFlags(); err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
fmt.Fprintf(os.Stderr, "ERROR: %v\n\n", err)
// Print the CLI help in case of error.
if err = rootCmd.Help(); err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n\n", err)
}
os.Exit(1)
}
initPFlags()

streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
rootCmd := cmd.NewCmdSHP(&streams)
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
os.Exit(1)
Expand All @@ -53,9 +59,13 @@ func main() {
// Any flags for "-h" or "--help" are ignored because pflag will show the usage later with all subcommands.
func initGoFlags() error {
flagset := goflag.NewFlagSet(ApplicationName, goflag.ContinueOnError)

// Discard usage and error message written to stdout and stderr in the "goflag" library.
// Instead, return the error only.
flagset.SetOutput(io.Discard)

goflag.CommandLine = flagset
klog.InitFlags(flagset)

args := []string{}
for _, arg := range os.Args[1:] {
if arg != "-h" && arg != "--help" {
Expand Down