@@ -32,11 +32,11 @@ import (
3232var (
3333 curlOptions = curl .NewOptionSet ()
3434
35- help bool
36- debug bool
37- usage string
38- flags * pflag.FlagSet
39- config * genericclioptions.ConfigFlags
35+ help bool
36+ debug bool
37+ options string
38+ flags * pflag.FlagSet
39+ config * genericclioptions.ConfigFlags
4040)
4141
4242func init () {
@@ -68,12 +68,15 @@ func init() {
6868 short = ""
6969 }
7070
71- flags .VarP (opt .Value , name , short , opt .Help )
71+ flag := flags .VarPF (opt .Value , name , short , opt .Help )
72+ if curl .IsBoolFlag (opt .Value ) {
73+ flag .NoOptDefVal = "true"
74+ }
7275 }
7376
7477 config = genericclioptions .NewConfigFlags (false )
7578 config .AddFlags (flags )
76- usage = flags .FlagUsages ()
79+ options = flags .FlagUsages ()
7780}
7881
7982func main () {
@@ -90,7 +93,7 @@ func run(ctx context.Context) error {
9093 flags .Parse (os .Args [1 :])
9194
9295 if help {
93- printUsage ( )
96+ fmt . Print ( usageAndOptions ( "Run curl against kubernetes pods" ) )
9497 return nil
9598 }
9699
@@ -111,8 +114,10 @@ func run(ctx context.Context) error {
111114 query , containerName = args [0 ], args [1 ]
112115 case 1 :
113116 query = args [0 ]
117+ case 0 :
118+ return usageError ("not enough arguments passed in the command line invocation of kubectl curl" )
114119 default :
115- return fmt . Errorf ("too many arguments passed in the command line invocation of kubectl curl [URL] [container] " )
120+ return usageError ("too many arguments passed in the command line invocation of kubectl curl" )
116121 }
117122
118123 if strings .Index (query , "://" ) < 0 {
@@ -299,13 +304,22 @@ func openPortForwarder(ctx context.Context, fwd portForwarderConfig) (*portforwa
299304 return portforward .New (dialer , ports , ctx .Done (), make (chan struct {}), fwd .stdout , fwd .stderr )
300305}
301306
302- func printUsage () {
303- fmt .Printf (`Run curl against kubernetes pods
307+ type usageError string
308+
309+ func (e usageError ) Error () string {
310+ return usage (string (e ))
311+ }
312+
313+ func usage (msg string ) string {
314+ return msg + `
304315
305316Usage:
306317 kubectl curl [options] URL [container]
318+ `
319+ }
307320
321+ func usageAndOptions (msg string ) string {
322+ return usage (msg ) + `
308323Options:
309- %s
310- ` , usage )
324+ ` + options
311325}
0 commit comments