-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcobrabuilder.go
2637 lines (2304 loc) · 116 KB
/
cobrabuilder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package boa
import (
"net"
"time"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
// CobraCmdBuilder is a builder for cobra.Command fields and chaining other
// helpful methods. Flags can be added to a command using builder methods as
// well.
type CobraCmdBuilder struct {
cmd *cobra.Command
}
// ToCobraCmdBuilder is used to convert an existing cobra.Command to a
// CobraCmdBuilder.
func ToCobraCmdBuilder(cmd *cobra.Command) *CobraCmdBuilder {
return &CobraCmdBuilder{cmd}
}
// NewCobraCmd creates a new CobraCmdBuilder and sets the use for the
// underlying cobra.Command
//
// Use is the one-line usage message.
// Recommended syntax is as follows:
//
// [ ] identifies an optional argument. Arguments that are not enclosed in brackets are required.
// ... indicates that you can specify multiple values for the previous argument.
// | indicates mutually exclusive information. You can use the argument to the left of the separator or the
// argument to the right of the separator. You cannot use both arguments in a single use of the command.
// { } delimits a set of mutually exclusive arguments when one of the arguments is required. If the arguments are
// optional, they are enclosed in brackets ([ ]).
//
// Example: add [-F file | -D dir]... [-f format] profile
func NewCobraCmd(use string) *CobraCmdBuilder {
return &CobraCmdBuilder{
cmd: &cobra.Command{
Use: use,
},
}
}
// WithAliases is an array of aliases that can be used instead of the first word
// in Use.
func (b *CobraCmdBuilder) WithAliases(aliases []string) *CobraCmdBuilder {
b.cmd.Aliases = aliases
return b
}
// SuggestFor is an array of command names for which this command will be
// suggested - similar to aliases but only suggests.
func (b *CobraCmdBuilder) SuggestFor(cmds []string) *CobraCmdBuilder {
b.cmd.SuggestFor = cmds
return b
}
// WithShortDescription is the short description shown in the 'help' output.
func (b *CobraCmdBuilder) WithShortDescription(short string) *CobraCmdBuilder {
b.cmd.Short = short
return b
}
// WithGroupId is the group id under which this subcommand is grouped in the
// 'help' output of its parent.
func (b *CobraCmdBuilder) WithGroupID(groupId string) *CobraCmdBuilder {
b.cmd.GroupID = groupId
return b
}
// WithLongDescription is the long message shown in the 'help <this-command>'
// output.
func (b *CobraCmdBuilder) WithLongDescription(long string) *CobraCmdBuilder {
b.cmd.Long = long
return b
}
// WithExample is examples of how to use the command.
func (b *CobraCmdBuilder) WithExample(example string) *CobraCmdBuilder {
b.cmd.Example = example
return b
}
// WithValidArgs is list of all valid non-flag arguments that are accepted in
// shell completions
func (b *CobraCmdBuilder) WithValidArgs(validArgs []string) *CobraCmdBuilder {
b.cmd.ValidArgs = append(b.cmd.ValidArgs, validArgs...)
return b
}
// WithValidArgsFunction is an optional function that provides valid non-flag
// arguments for shell completion. It is a dynamic version of using ValidArgs.
// Only one of ValidArgs and ValidArgsFunction can be used for a command.
func (b *CobraCmdBuilder) WithValidArgsFunction(validArgsFunc func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)) *CobraCmdBuilder {
b.cmd.ValidArgsFunction = validArgsFunc
return b
}
// WithArgs sets the expected arguments for the command.
//
// For example:
//
// WithArgs(cobra.MatchAll(cobra.MinimumNArgs(1), cobra.OnlyValidArgs))
func (b *CobraCmdBuilder) WithArgs(args cobra.PositionalArgs) *CobraCmdBuilder {
b.cmd.Args = args
return b
}
// WithArgAliases is List of aliases for ValidArgs. These are not suggested to
// the user in the shell completion, but accepted if entered manually.
func (b *CobraCmdBuilder) WithArgAliases(argAliases []string) *CobraCmdBuilder {
b.cmd.ArgAliases = argAliases
return b
}
// WithBashCompletionFunction is custom bash functions used by the legacy bash
// autocompletion generator. For portability with other shells, it is
// recommended to instead use ValidArgsFunction
func (b *CobraCmdBuilder) WithBashCompletionFunction(bashCompletionFunction string) *CobraCmdBuilder {
b.cmd.BashCompletionFunction = bashCompletionFunction
return b
}
// Deprecated defines if this command is deprecated and should print this string
// when used
func (b *CobraCmdBuilder) Deprecated(deprecated string) *CobraCmdBuilder {
b.cmd.Deprecated = deprecated
return b
}
// WithAnnotations are key/value pairs that can be used by applications to
// identify or group commands.
func (b *CobraCmdBuilder) WithAnnotations(annotations map[string]string) *CobraCmdBuilder {
b.cmd.Annotations = annotations
return b
}
// Version defines the version for this command. If this value is non-empty and
// the command does not define a "version" flag, a "version" boolean flag will
// be added to the command and, if specified, will print content of the
// "Version" variable. A shorthand "v" flag will also be added if the command
// does not define one.
func (b *CobraCmdBuilder) WithVersion(version string) *CobraCmdBuilder {
b.cmd.Version = version
return b
}
func (b *CobraCmdBuilder) WithNoOp() *CobraCmdBuilder {
return b.WithRunFunc(func(*cobra.Command, []string) {})
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithPersistentPreRunFunc: children of this command will inherit and execute.
func (b *CobraCmdBuilder) WithPersistentPreRunFunc(f func(cmd *cobra.Command, args []string)) *CobraCmdBuilder {
b.cmd.PersistentPreRun = f
return b
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithPersistentPreRunEFunc: PersistentPreRun but returns an error.
func (b *CobraCmdBuilder) WithPersistentPreRunEFunc(f func(cmd *cobra.Command, args []string) error) *CobraCmdBuilder {
b.cmd.PersistentPreRunE = f
return b
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithPreRunFunc: children of this command will not inherit.
func (b *CobraCmdBuilder) WithPreRunFunc(f func(cmd *cobra.Command, args []string)) *CobraCmdBuilder {
b.cmd.PreRun = f
return b
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithPreRunEFunc: PreRun but returns an error.
func (b *CobraCmdBuilder) WithPreRunEFunc(f func(cmd *cobra.Command, args []string) error) *CobraCmdBuilder {
b.cmd.PreRunE = f
return b
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithRunFunc: Typically the actual work function. Most commands will only
// implement this.
func (b *CobraCmdBuilder) WithRunFunc(f func(cmd *cobra.Command, args []string)) *CobraCmdBuilder {
b.cmd.Run = f
return b
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithRunEFunc: Run but returns an error.
func (b *CobraCmdBuilder) WithRunEFunc(f func(cmd *cobra.Command, args []string) error) *CobraCmdBuilder {
b.cmd.RunE = f
return b
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithPostRunFunc: run after the Run command.
func (b *CobraCmdBuilder) WithPostRunFunc(f func(cmd *cobra.Command, args []string)) *CobraCmdBuilder {
b.cmd.PostRun = f
return b
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithPostRunEFunc: PostRun but returns an error.
func (b *CobraCmdBuilder) WithPostRunEFunc(f func(cmd *cobra.Command, args []string) error) *CobraCmdBuilder {
b.cmd.PostRunE = f
return b
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithPersistentPostRunFunc: children of this command will inherit and execute
// after PostRun.
func (b *CobraCmdBuilder) WithPersistentPostRunFunc(f func(cmd *cobra.Command, args []string)) *CobraCmdBuilder {
b.cmd.PersistentPostRun = f
return b
}
// The *Run functions are executed in the following order:
// - PersistentPreRun()
// - PreRun()
// - Run()
// - PostRun()
// - PersistentPostRun()
//
// All functions get the same args, the arguments after the command name.
//
// WithPersistentPostRunEFunc: PersistentPostRun but returns an error.
func (b *CobraCmdBuilder) WithPersistentPostRunEFunc(f func(cmd *cobra.Command, args []string) error) *CobraCmdBuilder {
b.cmd.PersistentPostRunE = f
return b
}
// WithFParseErrWhitelist flag parse errors to be ignored.
func (b *CobraCmdBuilder) WithFParseErrWhitelist(flagParseErrors cobra.FParseErrWhitelist) *CobraCmdBuilder {
b.cmd.FParseErrWhitelist = flagParseErrors
return b
}
// WithCompletionOptions is a set of options to control the handling of shell
// completion.
func (b *CobraCmdBuilder) WithCompletionOptions(options cobra.CompletionOptions) *CobraCmdBuilder {
b.cmd.CompletionOptions = options
return b
}
// TraverseChildren parses flags on all parents before executing child command.
func (b *CobraCmdBuilder) TraverseChildren() *CobraCmdBuilder {
b.cmd.TraverseChildren = true
return b
}
// Hidden defines if this command is hidden and should NOT show up in the list
// of available commands.
func (b *CobraCmdBuilder) Hidden() *CobraCmdBuilder {
b.cmd.Hidden = true
return b
}
// SilenceErrors is an option to quiet errors down stream.
func (b *CobraCmdBuilder) SilenceErrors() *CobraCmdBuilder {
b.cmd.SilenceErrors = true
return b
}
// SilenceUsage is an option to silence usage when an error occurs.
func (b *CobraCmdBuilder) SilenceUsage() *CobraCmdBuilder {
b.cmd.SilenceUsage = true
return b
}
// DisableFlagParsing DisableFlagParsing disables the flag parsing. If this is
// true all flags will be passed to the command as arguments.
func (b *CobraCmdBuilder) DisableFlagParsing() *CobraCmdBuilder {
b.cmd.DisableFlagParsing = true
return b
}
// DisableAutoGenTag defines, if gen tag ("Auto generated by spf13/cobra...")
// will be printed by generating docs for this command.
func (b *CobraCmdBuilder) DisableAutoGenTag() *CobraCmdBuilder {
b.cmd.DisableAutoGenTag = true
return b
}
// DisableFlagsInUseLine will disable the addition of [flags] to the usage line
// of a command when printing help or generating docs
func (b *CobraCmdBuilder) DisableFlagsInUseLine() *CobraCmdBuilder {
b.cmd.DisableFlagsInUseLine = true
return b
}
// DisableSuggestions disables the suggestions based on Levenshtein distance
// that go along with 'unknown command' messages.
func (b *CobraCmdBuilder) DisableSuggestions() *CobraCmdBuilder {
b.cmd.DisableSuggestions = true
return b
}
// WithSuggestionsMinimumDistance defines minimum levenshtein distance to
// display suggestions. Must be > 0.
func (b *CobraCmdBuilder) WithSuggestionsMinimumDistance(distance int) *CobraCmdBuilder {
b.cmd.SuggestionsMinimumDistance = distance
return b
}
// WithSubCommands adds one or more commands to this parent command.
func (b *CobraCmdBuilder) WithSubCommands(cmds ...*cobra.Command) *CobraCmdBuilder {
b.cmd.AddCommand(cmds...)
return b
}
// WithUsageTemplate sets usage template. Can be defined by Application.
func (b *CobraCmdBuilder) WithUsageTemplate(template string) *CobraCmdBuilder {
b.cmd.SetUsageTemplate(template)
return b
}
// WithHelpTemplate sets help template to be used. Application can use it to set
// custom template.
func (b *CobraCmdBuilder) WithHelpTemplate(template string) *CobraCmdBuilder {
b.cmd.SetHelpTemplate(template)
return b
}
// WithUsageFunc sets usage function. Usage can be defined by application.
func (b *CobraCmdBuilder) WithUsageFunc(function func(*cobra.Command) error) *CobraCmdBuilder {
b.cmd.SetUsageFunc(function)
return b
}
// WithHelpFunc sets help function. Can be defined by Application.
func (b *CobraCmdBuilder) WithHelpFunc(function func(*cobra.Command, []string)) *CobraCmdBuilder {
b.cmd.SetHelpFunc(function)
return b
}
// WithBoolFlag defines a bool flag with specified name, default value, and
// usage string. The return value is the address of a bool variable that stores
// the value of the flag.
func (b *CobraCmdBuilder) WithBoolFlag(name string, value bool, usage string) *CobraCmdBuilder {
b.cmd.Flags().Bool(name, value, usage)
return b
}
// WithBoolPFlag BoolP is like Bool, but accepts a shorthand letter that can be
// used after a single dash.
func (b *CobraCmdBuilder) WithBoolPFlag(name string, shorthand string, value bool, usage string) *CobraCmdBuilder {
b.cmd.Flags().BoolP(name, shorthand, value, usage)
return b
}
// WithBoolVarFlag defines a bool flag with specified name, default value, and
// usage string. The argument p points to a bool variable in which to store the
// value of the flag.
func (b *CobraCmdBuilder) WithBoolVarFlag(variable *bool, name string, value bool, usage string) *CobraCmdBuilder {
b.cmd.Flags().BoolVar(variable, name, value, usage)
return b
}
// WithBoolVarPFlag is like BoolVar, but accepts a shorthand letter that can be
// used after a single dash.
func (b *CobraCmdBuilder) WithBoolVarPFlag(variable *bool, name string, shorthand string, value bool, usage string) *CobraCmdBuilder {
b.cmd.Flags().BoolVarP(variable, name, shorthand, value, usage)
return b
}
// WithBoolSliceFlag defines a []bool flag with specified name, default value,
// and usage string. The return value is the address of a []bool variable that
// stores the value of the flag.
func (b *CobraCmdBuilder) WithBoolSliceFlag(name string, value []bool, usage string) *CobraCmdBuilder {
b.cmd.Flags().BoolSlice(name, value, usage)
return b
}
// WithBoolSlicePFlag is like BoolSlice, but accepts a shorthand letter that
// can be used after a single dash.
func (b *CobraCmdBuilder) WithBoolSlicePFlag(name string, shorthand string, value []bool, usage string) *CobraCmdBuilder {
b.cmd.Flags().BoolSliceP(name, shorthand, value, usage)
return b
}
// WithBoolSliceVarFlag defines a boolSlice flag with specified name, default
// value, and usage string. The argument p points to a []bool variable in which
// to store the value of the flag.
func (b *CobraCmdBuilder) WithBoolSliceVarFlag(variable *[]bool, name string, value []bool, usage string) *CobraCmdBuilder {
b.cmd.Flags().BoolSliceVar(variable, name, value, usage)
return b
}
// WithBoolSliceVarPFlag is like BoolSliceVar, but accepts a shorthand letter
// that can be used after a single dash.
func (b *CobraCmdBuilder) WithBoolSliceVarPFlag(variable *[]bool, name string, shorthand string, value []bool, usage string) *CobraCmdBuilder {
b.cmd.Flags().BoolSliceVarP(variable, name, shorthand, value, usage)
return b
}
// WithBytesBase64Flag defines an []byte flag with specified name, default
// value, and usage string. The return value is the address of an []byte
// variable that stores the value of the flag.
func (b *CobraCmdBuilder) WithBytesBase64Flag(name string, value []byte, usage string) *CobraCmdBuilder {
b.cmd.Flags().BytesBase64(name, value, usage)
return b
}
// WithBytesBase64PFlag is like BytesBase64, but accepts a shorthand letter that
// can be used after a single dash.
func (b *CobraCmdBuilder) WithBytesBase64PFlag(name string, shorthand string, value []byte, usage string) *CobraCmdBuilder {
b.cmd.Flags().BytesBase64P(name, shorthand, value, usage)
return b
}
// WithBytesBase64VarFlag defines an []byte flag with specified name, default
// value, and usage string. The argument p points to an []byte variable in which
// to store the value of the flag.
func (b *CobraCmdBuilder) WithBytesBase64VarFlag(variable *[]byte, name string, value []byte, usage string) *CobraCmdBuilder {
b.cmd.Flags().BytesBase64Var(variable, name, value, usage)
return b
}
// WithBytesBase64VarPFlag BytesBase64VarP is like BytesBase64Var, but accepts a
// shorthand letter that can be used after a single dash.
func (b *CobraCmdBuilder) WithBytesBase64VarPFlag(variable *[]byte, name string, shorthand string, value []byte, usage string) *CobraCmdBuilder {
b.cmd.Flags().BytesBase64VarP(variable, name, shorthand, value, usage)
return b
}
// WithBytesHexFlag defines an []byte flag with specified name, default value,
// and usage string. The return value is the address of an []byte variable that
// stores the value of the flag.
func (b *CobraCmdBuilder) WithBytesHexFlag(name string, value []byte, usage string) *CobraCmdBuilder {
b.cmd.Flags().BytesHex(name, value, usage)
return b
}
// WithBytesHexPFlag is like BytesHex, but accepts a shorthand letter that can
// be used after a single dash.
func (b *CobraCmdBuilder) WithBytesHexPFlag(name string, shorthand string, value []byte, usage string) *CobraCmdBuilder {
b.cmd.Flags().BytesHexP(name, shorthand, value, usage)
return b
}
// WithBytesHexVarFlag BytesHexVar defines an []byte flag with specified name,
// default value, and usage string. The argument p points to an []byte variable
// in which to store the value of the flag.
func (b *CobraCmdBuilder) WithBytesHexVarFlag(variable *[]byte, name string, value []byte, usage string) *CobraCmdBuilder {
b.cmd.Flags().BytesHexVar(variable, name, value, usage)
return b
}
// WithBytesHexVarPFlag is like BytesHexVar, but accepts a shorthand letter that
// can be used after a single dash.
func (b *CobraCmdBuilder) WithBytesHexVarPFlag(variable *[]byte, name string, shorthand string, value []byte, usage string) *CobraCmdBuilder {
b.cmd.Flags().BytesHexVarP(variable, name, shorthand, value, usage)
return b
}
// WithCountFlag defines a count flag with specified name, default value, and
// usage string. The return value is the address of an int variable that stores
// the value of the flag. A count flag will add 1 to its value every time it is
// found on the command line.
func (b *CobraCmdBuilder) WithCountFlag(name string, usage string) *CobraCmdBuilder {
b.cmd.Flags().Count(name, usage)
return b
}
// WithCountPFlag is like Count only takes a shorthand for the flag name.
func (b *CobraCmdBuilder) WithCountPFlag(name string, shorthand string, usage string) *CobraCmdBuilder {
b.cmd.Flags().CountP(name, shorthand, usage)
return b
}
// WithCountVarFlag defines a count flag with specified name, default value, and
// usage string. The argument p points to an int variable in which to store the
// value of the flag. A count flag will add 1 to its value every time it is
// found on the command line
func (b *CobraCmdBuilder) WithCountVarFlag(variable *int, name string, usage string) *CobraCmdBuilder {
b.cmd.Flags().CountVar(variable, name, usage)
return b
}
// WithCountVarPFlag is like CountVar only take a shorthand for the flag name.
func (b *CobraCmdBuilder) WithCountVarPFlag(variable *int, name string, shorthand string, usage string) *CobraCmdBuilder {
b.cmd.Flags().CountVarP(variable, name, shorthand, usage)
return b
}
// WithDurationFlag defines a time.Duration flag with specified name, default
// value, and usage string. The return value is the address of a time.Duration
// variable that stores the value of the flag.
func (b *CobraCmdBuilder) WithDurationFlag(name string, value time.Duration, usage string) *CobraCmdBuilder {
b.cmd.Flags().Duration(name, value, usage)
return b
}
// WithDurationPFlag is like Duration, but accepts a shorthand letter that can
// be used after a single dash.
func (b *CobraCmdBuilder) WithDurationPFlag(name string, shorthand string, value time.Duration, usage string) *CobraCmdBuilder {
b.cmd.Flags().DurationP(name, shorthand, value, usage)
return b
}
// WithDurationVarFlag defines a time.Duration flag with specified name, default
// value, and usage string. The argument p points to a time.Duration variable in
// which to store the value of the flag.
func (b *CobraCmdBuilder) WithDurationVarFlag(variable *time.Duration, name string, value time.Duration, usage string) *CobraCmdBuilder {
b.cmd.Flags().DurationVar(variable, name, value, usage)
return b
}
// WithDurationVarPFlag is like DurationVar, but accepts a shorthand letter that
// can be used after a single dash.
func (b *CobraCmdBuilder) WithDurationVarPFlag(variable *time.Duration, name string, shorthand string, value time.Duration, usage string) *CobraCmdBuilder {
b.cmd.Flags().DurationVarP(variable, name, shorthand, value, usage)
return b
}
// WithDurationSliceFlag defines a []time.Duration flag with specified name,
// default value, and usage string. The return value is the address of a
// []time.Duration variable that stores the value of the flag.
func (b *CobraCmdBuilder) WithDurationSliceFlag(name string, value []time.Duration, usage string) *CobraCmdBuilder {
b.cmd.Flags().DurationSlice(name, value, usage)
return b
}
// WithDurationSlicePFlag is like DurationSlice, but accepts a shorthand letter
// that can be used after a single dash.
func (b *CobraCmdBuilder) WithDurationSlicePFlag(name string, shorthand string, value []time.Duration, usage string) *CobraCmdBuilder {
b.cmd.Flags().DurationSliceP(name, shorthand, value, usage)
return b
}
// WithDurationSliceVarFlag defines a durationSlice flag with specified name,
// default value, and usage string. The argument p points to a []time.Duration
// variable in which to store the value of the flag.
func (b *CobraCmdBuilder) WithDurationSliceVarFlag(variable *[]time.Duration, name string, value []time.Duration, usage string) *CobraCmdBuilder {
b.cmd.Flags().DurationSliceVar(variable, name, value, usage)
return b
}
// WithDurationSliceVarPFlag is like DurationSliceVar, but accepts a shorthand
// letter that can be used after a single dash.
func (b *CobraCmdBuilder) WithDurationSliceVarPFlag(variable *[]time.Duration, name string, shorthand string, value []time.Duration, usage string) *CobraCmdBuilder {
b.cmd.Flags().DurationSliceVarP(variable, name, shorthand, value, usage)
return b
}
// WithFloat32Flag defines a float32 flag with specified name, default value,
// and usage string. The return value is the address of a float32 variable that
// stores the value of the flag.
func (b *CobraCmdBuilder) WithFloat32Flag(name string, value float32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float32(name, value, usage)
return b
}
// WithFloat32PFlag is like Float32, but accepts a shorthand letter that can be
// used after a single dash.
func (b *CobraCmdBuilder) WithFloat32PFlag(name string, shorthand string, value float32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float32P(name, shorthand, value, usage)
return b
}
// WithFloat32VarFlag defines a float32 flag with specified name, default value,
// and usage string. The argument p points to a float32 variable in which to
// store the value of the flag.
func (b *CobraCmdBuilder) WithFloat32VarFlag(variable *float32, name string, value float32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float32Var(variable, name, value, usage)
return b
}
// WithFloat32VarPFlag is like Float32Var, but accepts a shorthand letter that
// can be used after a single dash.
func (b *CobraCmdBuilder) WithFloat32VarPFlag(variable *float32, name string, shorthand string, value float32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float32VarP(variable, name, shorthand, value, usage)
return b
}
// WithFloat32SliceFlag defines a []float32 flag with specified name, default
// value, and usage string. The return value is the address of a []float32
// variable that stores the value of the flag.
func (b *CobraCmdBuilder) WithFloat32SliceFlag(name string, value []float32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float32Slice(name, value, usage)
return b
}
// WithFloat32SlicePFlag is like Float32Slice, but accepts a shorthand letter
// that can be used after a single dash.
func (b *CobraCmdBuilder) WithFloat32SlicePFlag(name string, shorthand string, value []float32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float32SliceP(name, shorthand, value, usage)
return b
}
// WithFloat32SliceVarFlag defines a float32Slice flag with specified name,
// default value, and usage string. The argument p points to a []float32
// variable in which to store the value of the flag.
func (b *CobraCmdBuilder) WithFloat32SliceVarFlag(variable *[]float32, name string, value []float32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float32SliceVar(variable, name, value, usage)
return b
}
// WithFloat32SliceVarPFlag is like Float32SliceVar, but accepts a shorthand
// letter that can be used after a single dash.
func (b *CobraCmdBuilder) WithFloat32SliceVarPFlag(variable *[]float32, name string, shorthand string, value []float32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float32SliceVarP(variable, name, shorthand, value, usage)
return b
}
// WithFloat64Flag defines a float64 flag with specified name, default value,
// and usage string. The return value is the address of a float64 variable that
// stores the value of the flag.
func (b *CobraCmdBuilder) WithFloat64Flag(name string, value float64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float64(name, value, usage)
return b
}
// WithFloat64PFlag is like Float64, but accepts a shorthand letter that can be
// used after a single dash.
func (b *CobraCmdBuilder) WithFloat64PFlag(name string, shorthand string, value float64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float64P(name, shorthand, value, usage)
return b
}
// WithFloat64VarFlag defines a float64 flag with specified name, default value,
// and usage string. The argument p points to a float64 variable in which to
// store the value of the flag.
func (b *CobraCmdBuilder) WithFloat64VarFlag(variable *float64, name string, value float64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float64Var(variable, name, value, usage)
return b
}
// WithFloat64VarPFlag is like Float64Var, but accepts a shorthand letter that
// can be used after a single dash.
func (b *CobraCmdBuilder) WithFloat64VarPFlag(variable *float64, name string, shorthand string, value float64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float64VarP(variable, name, shorthand, value, usage)
return b
}
// WithFloat64SliceFlag defines a []float64 flag with specified name, default
// value, and usage string. The return value is the address of a []float64
// variable that stores the value of the flag.
func (b *CobraCmdBuilder) WithFloat64SliceFlag(name string, value []float64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float64Slice(name, value, usage)
return b
}
// WithFloat64SlicePFlag is like Float64Slice, but accepts a shorthand letter
// that can be used after a single dash.
func (b *CobraCmdBuilder) WithFloat64SlicePFlag(name string, shorthand string, value []float64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float64SliceP(name, shorthand, value, usage)
return b
}
// WithFloat64SliceVarFlag defines a float64Slice flag with specified name,
// default value, and usage string. The argument p points to a []float64
// variable in which to store the value of the flag.
func (b *CobraCmdBuilder) WithFloat64SliceVarFlag(variable *[]float64, name string, value []float64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float64SliceVar(variable, name, value, usage)
return b
}
// WithFloat64SliceVarPFlag is like Float64SliceVar, but accepts a shorthand
// letter that can be used after a single dash.
func (b *CobraCmdBuilder) WithFloat64SliceVarPFlag(variable *[]float64, name string, shorthand string, value []float64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Float64SliceVarP(variable, name, shorthand, value, usage)
return b
}
// WithIntFlag defines an int flag with specified name, default value, and usage
// string. The return value is the address of an int variable that stores the
// value of the flag.
func (b *CobraCmdBuilder) WithIntFlag(name string, value int, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int(name, value, usage)
return b
}
// WithIntPFlag is like Int, but accepts a shorthand letter that can be used
// after a single dash.
func (b *CobraCmdBuilder) WithIntPFlag(name string, shorthand string, value int, usage string) *CobraCmdBuilder {
b.cmd.Flags().IntP(name, shorthand, value, usage)
return b
}
// WithIntVarFlag defines an int flag with specified name, default value, and
// usage string. The argument p points to an int variable in which to store the
// value of the flag.
func (b *CobraCmdBuilder) WithIntVarFlag(variable *int, name string, value int, usage string) *CobraCmdBuilder {
b.cmd.Flags().IntVar(variable, name, value, usage)
return b
}
// WithIntVarPFlag is like IntVar, but accepts a shorthand letter that can be
// used after a single dash.
func (b *CobraCmdBuilder) WithIntVarPFlag(variable *int, name string, shorthand string, value int, usage string) *CobraCmdBuilder {
b.cmd.Flags().IntVarP(variable, name, shorthand, value, usage)
return b
}
// WithIntSliceFlag defines a []int flag with specified name, default value, and
// usage string. The return value is the address of a []int variable that stores
// the value of the flag.
func (b *CobraCmdBuilder) WithIntSliceFlag(name string, value []int, usage string) *CobraCmdBuilder {
b.cmd.Flags().IntSlice(name, value, usage)
return b
}
// WithIntSlicePFlag is like IntSlice, but accepts a shorthand letter that can
// be used after a single dash.
func (b *CobraCmdBuilder) WithIntSlicePFlag(name string, shorthand string, value []int, usage string) *CobraCmdBuilder {
b.cmd.Flags().IntSliceP(name, shorthand, value, usage)
return b
}
// WithIntSliceVarFlag defines a intSlice flag with specified name, default
// value, and usage string. The argument p points to a []int variable in which
// to store the value of the flag.
func (b *CobraCmdBuilder) WithIntSliceVarFlag(variable *[]int, name string, value []int, usage string) *CobraCmdBuilder {
b.cmd.Flags().IntSliceVar(variable, name, value, usage)
return b
}
// WithIntSliceVarPFlag is like IntSliceVar, but accepts a shorthand letter that
// can be used after a single dash.
func (b *CobraCmdBuilder) WithIntSliceVarPFlag(variable *[]int, name string, shorthand string, value []int, usage string) *CobraCmdBuilder {
b.cmd.Flags().IntSliceVarP(variable, name, shorthand, value, usage)
return b
}
// WithInt8Flag defines an int8 flag with specified name, default value, and
// usage string. The return value is the address of an int8 variable that stores
// the value of the flag.
func (b *CobraCmdBuilder) WithInt8Flag(name string, value int8, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int8(name, value, usage)
return b
}
// WithInt8PFlag is like Int8, but accepts a shorthand letter that can be used
// after a single dash.
func (b *CobraCmdBuilder) WithInt8PFlag(name string, shorthand string, value int8, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int8P(name, shorthand, value, usage)
return b
}
// WithInt8VarFlag defines an int8 flag with specified name, default value, and
// usage string. The argument p points to an int8 variable in which to store the
// value of the flag.
func (b *CobraCmdBuilder) WithInt8VarFlag(variable *int8, name string, value int8, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int8Var(variable, name, value, usage)
return b
}
// WithInt8VarPFlag is like Int8Var, but accepts a shorthand letter that can be
// used after a single dash.
func (b *CobraCmdBuilder) WithInt8VarPFlag(variable *int8, name string, shorthand string, value int8, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int8VarP(variable, name, shorthand, value, usage)
return b
}
// WithInt16Flag defines an int16 flag with specified name, default value, and
// usage string. The return value is the address of an int16 variable that
// stores the value of the flag.
func (b *CobraCmdBuilder) WithInt16Flag(name string, value int16, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int16(name, value, usage)
return b
}
// WithInt16PFlag is like Int16, but accepts a shorthand letter that can be used
// after a single dash.
func (b *CobraCmdBuilder) WithInt16PFlag(name string, shorthand string, value int16, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int16P(name, shorthand, value, usage)
return b
}
// WithInt16VarFlag defines an int16 flag with specified name, default value,
// and usage string. The argument p points to an int16 variable in which to
// store the value of the flag.
func (b *CobraCmdBuilder) WithInt16VarFlag(variable *int16, name string, value int16, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int16Var(variable, name, value, usage)
return b
}
// WithInt16VarPFlag is like Int16Var, but accepts a shorthand letter that can
// be used after a single dash.
func (b *CobraCmdBuilder) WithInt16VarPFlag(variable *int16, name string, shorthand string, value int16, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int16VarP(variable, name, shorthand, value, usage)
return b
}
// WithInt32Flag defines an int32 flag with specified name, default value, and
// usage string. The return value is the address of an int32 variable that
// stores the value of the flag.
func (b *CobraCmdBuilder) WithInt32Flag(name string, value int32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int32(name, value, usage)
return b
}
// WithInt32PFlag is like Int32, but accepts a shorthand letter that can be used
// after a single dash.
func (b *CobraCmdBuilder) WithInt32PFlag(name string, shorthand string, value int32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int32P(name, shorthand, value, usage)
return b
}
// WithInt32VarFlag defines an int32 flag with specified name, default value,
// and usage string. The argument p points to an int32 variable in which to
// store the value of the flag.
func (b *CobraCmdBuilder) WithInt32VarFlag(variable *int32, name string, value int32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int32Var(variable, name, value, usage)
return b
}
// WithInt32VarPFlag is like Int32Var, but accepts a shorthand letter that can
// be used after a single dash.
func (b *CobraCmdBuilder) WithInt32VarPFlag(variable *int32, name string, shorthand string, value int32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int32VarP(variable, name, shorthand, value, usage)
return b
}
// WithInt32SliceFlag defines a []int32 flag with specified name, default value,
// and usage string. The return value is the address of a []int32 variable that
// stores the value of the flag.
func (b *CobraCmdBuilder) WithInt32SliceFlag(name string, value []int32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int32Slice(name, value, usage)
return b
}
// WithInt32SlicePFlag is like Int32Slice, but accepts a shorthand letter that
// can be used after a single dash.
func (b *CobraCmdBuilder) WithInt32SlicePFlag(name string, shorthand string, value []int32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int32SliceP(name, shorthand, value, usage)
return b
}
// WithInt32SliceVarFlag defines a int32Slice flag with specified name, default
// value, and usage string. The argument p points to a []int32 variable in which
// to store the value of the flag.
func (b *CobraCmdBuilder) WithInt32SliceVarFlag(variable *[]int32, name string, value []int32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int32SliceVar(variable, name, value, usage)
return b
}
// WithInt32SliceVarPFlag is like Int32SliceVar, but accepts a shorthand letter
// that can be used after a single dash.
func (b *CobraCmdBuilder) WithInt32SliceVarPFlag(variable *[]int32, name string, shorthand string, value []int32, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int32SliceVarP(variable, name, shorthand, value, usage)
return b
}
// WithInt64Flag defines an int64 flag with specified name, default value, and
// usage string. The return value is the address of an int64 variable that
// stores the value of the flag.
func (b *CobraCmdBuilder) WithInt64Flag(name string, value int64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int64(name, value, usage)
return b
}
// WithInt64PFlag is like Int64, but accepts a shorthand letter that can be used
// after a single dash.
func (b *CobraCmdBuilder) WithInt64PFlag(name string, shorthand string, value int64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int64P(name, shorthand, value, usage)
return b
}
// WithInt64VarFlag defines an int64 flag with specified name, default value,
// and usage string. The argument p points to an int64 variable in which to
// store the value of the flag.
func (b *CobraCmdBuilder) WithInt64VarFlag(variable *int64, name string, value int64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int64Var(variable, name, value, usage)
return b
}
// WithInt64VarPFlag is like Int64Var, but accepts a shorthand letter that can
// be used after a single dash.
func (b *CobraCmdBuilder) WithInt64VarPFlag(variable *int64, name string, shorthand string, value int64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int64VarP(variable, name, shorthand, value, usage)
return b
}
// WithInt64SliceFlag defines a []int64 flag with specified name, default value,
// and usage string. The return value is the address of a []int64 variable that
// stores the value of the flag.
func (b *CobraCmdBuilder) WithInt64SliceFlag(name string, value []int64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int64Slice(name, value, usage)
return b
}
// WithInt64SlicePFlag is like Int64Slice, but accepts a shorthand letter that
// can be used after a single dash.
func (b *CobraCmdBuilder) WithInt64SlicePFlag(name string, shorthand string, value []int64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int64SliceP(name, shorthand, value, usage)
return b
}
// WithInt64SliceVarFlag defines a int64Slice flag with specified name, default
// value, and usage string. The argument p points to a []int64 variable in which
// to store the value of the flag.
func (b *CobraCmdBuilder) WithInt64SliceVarFlag(variable *[]int64, name string, value []int64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int64SliceVar(variable, name, value, usage)
return b
}
// WithInt64SliceVarPFlag is like Int64SliceVar, but accepts a shorthand letter
// that can be used after a single dash.
func (b *CobraCmdBuilder) WithInt64SliceVarPFlag(variable *[]int64, name string, shorthand string, value []int64, usage string) *CobraCmdBuilder {
b.cmd.Flags().Int64SliceVarP(variable, name, shorthand, value, usage)
return b
}
// WithUintFlag defines a uint flag with specified name, default value, and
// usage string. The return value is the address of a uint variable that stores
// the value of the flag.
func (b *CobraCmdBuilder) WithUintFlag(name string, value uint, usage string) *CobraCmdBuilder {
b.cmd.Flags().Uint(name, value, usage)
return b
}
// WithIntPFlag is like Uint, but accepts a shorthand letter that can be used
// after a single dash.
func (b *CobraCmdBuilder) WithUintPFlag(name string, shorthand string, value uint, usage string) *CobraCmdBuilder {
b.cmd.Flags().UintP(name, shorthand, value, usage)
return b
}
// WithUintVarFlag defines a uint flag with specified name, default value, and
// usage string. The argument p points to a uint variable in which to store the
// value of the flag.
func (b *CobraCmdBuilder) WithUintVarFlag(variable *uint, name string, value uint, usage string) *CobraCmdBuilder {
b.cmd.Flags().UintVar(variable, name, value, usage)
return b