forked from urfave/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
godoc-current.txt
2670 lines (1949 loc) · 83.3 KB
/
godoc-current.txt
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 cli // import "github.com/urfave/cli/v3"
Package cli provides a minimal framework for creating and organizing command
line Go applications. cli is designed to be easy to understand and write,
the most simple cli application can be written as follows:
func main() {
(&cli.App{}).Run(os.Args)
}
Of course this application does not do much, so let's make this an actual
application:
func main() {
app := &cli.App{
Name: "greet",
Usage: "say a greeting",
Action: func(c *cli.Context) error {
fmt.Println("Greetings")
return nil
},
}
app.Run(os.Args)
}
VARIABLES
var (
SuggestFlag SuggestFlagFunc = suggestFlag
SuggestCommand SuggestCommandFunc = suggestCommand
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
)
var AppHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}
USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
VERSION:
{{.Version}}{{end}}{{end}}{{if .Description}}
DESCRIPTION:
{{template "descriptionTemplate" .}}{{end}}
{{- if len .Authors}}
AUTHOR{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}}
COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
GLOBAL OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}}
COPYRIGHT:
{{template "copyrightTemplate" .}}{{end}}
`
AppHelpTemplate is the text template for the Default help topic. cli.go
uses text/template to render templates. You can render custom help text by
setting this variable.
var CommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}
USAGE:
{{template "usageTemplate" .}}{{if .Category}}
CATEGORY:
{{.Category}}{{end}}{{if .Description}}
DESCRIPTION:
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
`
CommandHelpTemplate is the text template for the command help topic. cli.go
uses text/template to render templates. You can render custom help text by
setting this variable.
var ErrWriter io.Writer = os.Stderr
ErrWriter is used to write errors to the user. This can be anything
implementing the io.Writer interface and defaults to os.Stderr.
var FishCompletionTemplate = `# {{ .App.Name }} fish shell completion
function __fish_{{ .App.Name }}_no_subcommand --description 'Test if there has been any subcommand yet'
for i in (commandline -opc)
if contains -- $i{{ range $v := .AllCommands }} {{ $v }}{{ end }}
return 1
end
end
return 0
end
{{ range $v := .Completions }}{{ $v }}
{{ end }}`
var MarkdownDocTemplate = `{{if gt .SectionNum 0}}% {{ .App.Name }} {{ .SectionNum }}
{{end}}# NAME
{{ .App.Name }}{{ if .App.Usage }} - {{ .App.Usage }}{{ end }}
# SYNOPSIS
{{ .App.Name }}
{{ if .SynopsisArgs }}
` + "```" + `
{{ range $v := .SynopsisArgs }}{{ $v }}{{ end }}` + "```" + `
{{ end }}{{ if .App.Description }}
# DESCRIPTION
{{ .App.Description }}
{{ end }}
**Usage**:
` + "```" + `{{ if .App.UsageText }}
{{ .App.UsageText }}
{{ else }}
{{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
{{ end }}` + "```" + `
{{ if .GlobalArgs }}
# GLOBAL OPTIONS
{{ range $v := .GlobalArgs }}
{{ $v }}{{ end }}
{{ end }}{{ if .Commands }}
# COMMANDS
{{ range $v := .Commands }}
{{ $v }}{{ end }}{{ end }}`
var OsExiter = os.Exit
OsExiter is the function used when the app exits. If not set defaults to
os.Exit.
var SubcommandHelpTemplate = `NAME:
{{template "helpNameTemplate" .}}
USAGE:
{{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}}
DESCRIPTION:
{{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}}
COMMANDS:{{template "visibleCommandTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
`
SubcommandHelpTemplate is the text template for the subcommand help topic.
cli.go uses text/template to render templates. You can render custom help
text by setting this variable.
var VersionPrinter = printVersion
VersionPrinter prints the version for the App
var HelpPrinter helpPrinter = printHelp
HelpPrinter is a function that writes the help output. If not set
explicitly, this calls HelpPrinterCustom using only the default template
functions.
If custom logic for printing help is required, this function can be
overridden. If the ExtraInfo field is defined on an App, this function
should not be modified, as HelpPrinterCustom will be used directly in order
to capture the extra information.
var HelpPrinterCustom helpPrinterCustom = printHelpCustom
HelpPrinterCustom is a function that writes the help output. It is used as
the default implementation of HelpPrinter, and may be called directly if the
ExtraInfo field is set on an App.
In the default implementation, if the customFuncs argument contains a
"wrapAt" key, which is a function which takes no arguments and returns an
int, this int value will be used to produce a "wrap" function used by the
default template to wrap long lines.
FUNCTIONS
func DefaultAppComplete(cCtx *Context)
DefaultAppComplete prints the list of subcommands as the default app
completion method
func DefaultCompleteWithFlags(cmd *Command) func(cCtx *Context)
func FlagNames(name string, aliases []string) []string
func HandleAction(action interface{}, cCtx *Context) (err error)
HandleAction attempts to figure out which Action signature was used.
If it's an ActionFunc or a func with the legacy signature for Action,
the func is run!
func HandleExitCoder(err error)
HandleExitCoder handles errors implementing ExitCoder by printing their
message and calling OsExiter with the given exit code.
If the given error instead implements MultiError, each error will be checked
for the ExitCoder interface, and OsExiter will be called with the last exit
code found, or exit code 1 if no ExitCoder is found.
This function is the default error-handling behavior for an App.
func ShowAppHelp(cCtx *Context) error
ShowAppHelp is an action that displays the help.
func ShowAppHelpAndExit(c *Context, exitCode int)
ShowAppHelpAndExit - Prints the list of subcommands for the app and exits
with exit code.
func ShowCommandCompletions(ctx *Context, command string)
ShowCommandCompletions prints the custom completions for a given command
func ShowCommandHelp(ctx *Context, command string) error
ShowCommandHelp prints help for the given command
func ShowCommandHelpAndExit(c *Context, command string, code int)
ShowCommandHelpAndExit - exits with code after showing help
func ShowCompletions(cCtx *Context)
ShowCompletions prints the lists of commands within a given context
func ShowSubcommandHelp(cCtx *Context) error
ShowSubcommandHelp prints help for the given subcommand
func ShowSubcommandHelpAndExit(c *Context, exitCode int)
ShowSubcommandHelpAndExit - Prints help for the given subcommand and exits
with exit code.
func ShowVersion(cCtx *Context)
ShowVersion prints the version number of the App
TYPES
type ActionFunc func(*Context) error
ActionFunc is the action to execute when no subcommands are specified
type ActionableFlag interface {
Flag
RunAction(*Context) error
}
ActionableFlag is an interface that wraps Flag interface and RunAction
operation.
type AfterFunc func(*Context) error
AfterFunc is an action to execute after any subcommands are run, but after
the subcommand has finished it is run even if Action() panics
type App struct {
// The name of the program. Defaults to path.Base(os.Args[0])
Name string
// Full name of command for help, defaults to Name
HelpName string
// Description of the program.
Usage string
// Text to override the USAGE section of help
UsageText string
// Description of the program argument format.
ArgsUsage string
// Version of the program
Version string
// Description of the program
Description string
// DefaultCommand is the (optional) name of a command
// to run if no command names are passed as CLI arguments.
DefaultCommand string
// List of commands to execute
Commands []*Command
// List of flags to parse
Flags []Flag
// Boolean to enable bash completion commands
EnableBashCompletion bool
// Boolean to hide built-in help command and help flag
HideHelp bool
// Boolean to hide built-in help command but keep help flag.
// Ignored if HideHelp is true.
HideHelpCommand bool
// Boolean to hide built-in version flag and the VERSION section of help
HideVersion bool
// An action to execute when the shell completion flag is set
BashComplete BashCompleteFunc
// An action to execute before any subcommands are run, but after the context is ready
// If a non-nil error is returned, no subcommands are run
Before BeforeFunc
// An action to execute after any subcommands are run, but after the subcommand has finished
// It is run even if Action() panics
After AfterFunc
// The action to execute when no subcommands are specified
Action ActionFunc
// Execute this function if the proper command cannot be found
CommandNotFound CommandNotFoundFunc
// Execute this function if a usage error occurs
OnUsageError OnUsageErrorFunc
// Execute this function when an invalid flag is accessed from the context
InvalidFlagAccessHandler InvalidFlagAccessFunc
// Compilation date
Compiled time.Time
// List of all authors who contributed
Authors []*Author
// Copyright of the binary if any
Copyright string
// Reader reader to write input to (useful for tests)
Reader io.Reader
// Writer writer to write output to
Writer io.Writer
// ErrWriter writes error output
ErrWriter io.Writer
// ExitErrHandler processes any error encountered while running an App before
// it is returned to the caller. If no function is provided, HandleExitCoder
// is used as the default behavior.
ExitErrHandler ExitErrHandlerFunc
// Other custom info
Metadata map[string]interface{}
// Carries a function which returns app specific info.
ExtraInfo func() map[string]string
// CustomAppHelpTemplate the text template for app help topic.
// cli.go uses text/template to render templates. You can
// render custom help text by setting this variable.
CustomAppHelpTemplate string
// SliceFlagSeparator is used to customize the separator for SliceFlag, the default is ","
SliceFlagSeparator string
// Boolean to enable short-option handling so user can combine several
// single-character bool arguments into one
// i.e. foobar -o -v -> foobar -ov
UseShortOptionHandling bool
// Enable suggestions for commands and flags
Suggest bool
// Allows global flags set by libraries which use flag.XXXVar(...) directly
// to be parsed through this library
AllowExtFlags bool
// Treat all flags as normal arguments if true
SkipFlagParsing bool
// Has unexported fields.
}
App is the main structure of a cli application. It is recommended that an
app be created with the cli.NewApp() function
func NewApp() *App
NewApp creates a new cli Application with some reasonable defaults for Name,
Usage, Version and Action.
func (a *App) Command(name string) *Command
Command returns the named command on App. Returns nil if the command does
not exist
func (a *App) Run(arguments []string) (err error)
Run is the entry point to the cli app. Parses the arguments slice and routes
to the proper flag/args combination
func (a *App) RunAndExitOnError()
RunAndExitOnError calls .Run() and exits non-zero if an error was returned
Deprecated: instead you should return an error that fulfills cli.ExitCoder
to cli.App.Run. This will cause the application to exit with the given error
code in the cli.ExitCoder
func (a *App) RunAsSubcommand(ctx *Context) (err error)
This is a stub function to keep public API unchanged from old code
Deprecated: use App.Run or App.RunContext
func (a *App) RunContext(ctx context.Context, arguments []string) (err error)
RunContext is like Run except it takes a Context that will be passed to
its commands and sub-commands. Through this, you can propagate timeouts and
cancellation requests
func (a *App) Setup()
Setup runs initialization code to ensure all data structures are ready
for `Run` or inspection prior to `Run`. It is internally called by `Run`,
but will return early if setup has already happened.
func (a *App) ToFishCompletion() (string, error)
ToFishCompletion creates a fish completion string for the `*App` The
function errors if either parsing or writing of the string fails.
func (a *App) ToMan() (string, error)
ToMan creates a man page string for the `*App` The function errors if either
parsing or writing of the string fails.
func (a *App) ToManWithSection(sectionNumber int) (string, error)
ToMan creates a man page string with section number for the `*App` The
function errors if either parsing or writing of the string fails.
func (a *App) ToMarkdown() (string, error)
ToMarkdown creates a markdown string for the `*App` The function errors if
either parsing or writing of the string fails.
func (a *App) VisibleCategories() []CommandCategory
VisibleCategories returns a slice of categories and commands that are
Hidden=false
func (a *App) VisibleCommands() []*Command
VisibleCommands returns a slice of the Commands with Hidden=false
func (a *App) VisibleFlagCategories() []VisibleFlagCategory
VisibleFlagCategories returns a slice containing all the categories with the
flags they contain
func (a *App) VisibleFlags() []Flag
VisibleFlags returns a slice of the Flags with Hidden=false
type Args interface {
// Get returns the nth argument, or else a blank string
Get(n int) string
// First returns the first argument, or else a blank string
First() string
// Tail returns the rest of the arguments (not the first one)
// or else an empty string slice
Tail() []string
// Len returns the length of the wrapped slice
Len() int
// Present checks if there are any arguments present
Present() bool
// Slice returns a copy of the internal slice
Slice() []string
}
type Author struct {
Name string // The Authors name
Email string // The Authors email
}
Author represents someone who has contributed to a cli project.
func (a *Author) String() string
String makes Author comply to the Stringer interface, to allow an easy print
in the templating process
type BashCompleteFunc func(*Context)
BashCompleteFunc is an action to execute when the shell completion flag is
set
type BeforeFunc func(*Context) error
BeforeFunc is an action to execute before any subcommands are run, but after
the context is ready if a non-nil error is returned, no subcommands are run
type BoolFlag struct {
Name string
Category string
DefaultText string
FilePath string
Usage string
Required bool
Hidden bool
HasBeenSet bool
Value bool
Destination *bool
Aliases []string
EnvVars []string
Count *int
Action func(*Context, bool) error
// Has unexported fields.
}
BoolFlag is a flag with type bool
func (f *BoolFlag) Apply(set *flag.FlagSet) error
Apply populates the flag given the flag set and environment
func (f *BoolFlag) Get(ctx *Context) bool
Get returns the flag’s value in the given Context.
func (f *BoolFlag) GetCategory() string
GetCategory returns the category of the flag
func (f *BoolFlag) GetDefaultText() string
GetDefaultText returns the default text for this flag
func (f *BoolFlag) GetEnvVars() []string
GetEnvVars returns the env vars for this flag
func (f *BoolFlag) GetUsage() string
GetUsage returns the usage string for the flag
func (f *BoolFlag) GetValue() string
GetValue returns the flags value as string representation and an empty
string if the flag takes no value at all.
func (f *BoolFlag) IsRequired() bool
IsRequired returns whether or not the flag is required
func (f *BoolFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file
func (f *BoolFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false
func (f *BoolFlag) Names() []string
Names returns the names of the flag
func (f *BoolFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *BoolFlag) String() string
String returns a readable representation of this value (for usage defaults)
func (f *BoolFlag) TakesValue() bool
TakesValue returns true if the flag takes a value, otherwise false
type CategorizableFlag interface {
VisibleFlag
// Returns the category of the flag
GetCategory() string
}
CategorizableFlag is an interface that allows us to potentially use a flag
in a categorized representation.
type Command struct {
// The name of the command
Name string
// A list of aliases for the command
Aliases []string
// A short description of the usage of this command
Usage string
// Custom text to show on USAGE section of help
UsageText string
// A longer explanation of how the command works
Description string
// A short description of the arguments of this command
ArgsUsage string
// The category the command is part of
Category string
// The function to call when checking for bash command completions
BashComplete BashCompleteFunc
// An action to execute before any sub-subcommands are run, but after the context is ready
// If a non-nil error is returned, no sub-subcommands are run
Before BeforeFunc
// An action to execute after any subcommands are run, but after the subcommand has finished
// It is run even if Action() panics
After AfterFunc
// The function to call when this command is invoked
Action ActionFunc
// Execute this function if a usage error occurs.
OnUsageError OnUsageErrorFunc
// List of child commands
Subcommands []*Command
// List of flags to parse
Flags []Flag
// Treat all flags as normal arguments if true
SkipFlagParsing bool
// Boolean to hide built-in help command and help flag
HideHelp bool
// Boolean to hide built-in help command but keep help flag
// Ignored if HideHelp is true.
HideHelpCommand bool
// Boolean to hide this command from help or completion
Hidden bool
// Boolean to enable short-option handling so user can combine several
// single-character bool arguments into one
// i.e. foobar -o -v -> foobar -ov
UseShortOptionHandling bool
// Full name of command for help, defaults to full command name, including parent commands.
HelpName string
// CustomHelpTemplate the text template for the command help topic.
// cli.go uses text/template to render templates. You can
// render custom help text by setting this variable.
CustomHelpTemplate string
// Has unexported fields.
}
Command is a subcommand for a cli.App.
func (cmd *Command) Command(name string) *Command
func (c *Command) FullName() string
FullName returns the full name of the command. For subcommands this ensures
that parent commands are part of the command path
func (c *Command) HasName(name string) bool
HasName returns true if Command.Name matches given name
func (c *Command) Names() []string
Names returns the names including short names and aliases.
func (c *Command) Run(cCtx *Context, arguments ...string) (err error)
func (c *Command) VisibleCategories() []CommandCategory
VisibleCategories returns a slice of categories and commands that are
Hidden=false
func (c *Command) VisibleCommands() []*Command
VisibleCommands returns a slice of the Commands with Hidden=false
func (c *Command) VisibleFlagCategories() []VisibleFlagCategory
VisibleFlagCategories returns a slice containing all the visible flag
categories with the flags they contain
func (c *Command) VisibleFlags() []Flag
VisibleFlags returns a slice of the Flags with Hidden=false
type CommandCategories interface {
// AddCommand adds a command to a category, creating a new category if necessary.
AddCommand(category string, command *Command)
// Categories returns a slice of categories sorted by name
Categories() []CommandCategory
}
CommandCategories interface allows for category manipulation
type CommandCategory interface {
// Name returns the category name string
Name() string
// VisibleCommands returns a slice of the Commands with Hidden=false
VisibleCommands() []*Command
}
CommandCategory is a category containing commands.
type CommandNotFoundFunc func(*Context, string)
CommandNotFoundFunc is executed if the proper command cannot be found
type Commands []*Command
type CommandsByName []*Command
func (c CommandsByName) Len() int
func (c CommandsByName) Less(i, j int) bool
func (c CommandsByName) Swap(i, j int)
type Context struct {
context.Context
App *App
Command *Command
// Has unexported fields.
}
Context is a type that is passed through to each Handler action in a cli
application. Context can be used to retrieve context-specific args and
parsed command-line options.
func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context
NewContext creates a new context. For use in when invoking an App or Command
action.
func (cCtx *Context) Args() Args
Args returns the command line arguments associated with the context.
func (cCtx *Context) Bool(name string) bool
Bool looks up the value of a local BoolFlag, returns false if not found
func (cCtx *Context) Count(name string) int
Count returns the num of occurences of this flag
func (cCtx *Context) Duration(name string) time.Duration
Duration looks up the value of a local DurationFlag, returns 0 if not found
func (cCtx *Context) FlagNames() []string
FlagNames returns a slice of flag names used by the this context and all of
its parent contexts.
func (cCtx *Context) Float64(name string) float64
Float64 looks up the value of a local Float64Flag, returns 0 if not found
func (cCtx *Context) Float64Slice(name string) []float64
Float64Slice looks up the value of a local Float64SliceFlag, returns nil if
not found
func (cCtx *Context) Generic(name string) interface{}
Generic looks up the value of a local GenericFlag, returns nil if not found
func (cCtx *Context) Int(name string) int
Int looks up the value of a local IntFlag, returns 0 if not found
func (cCtx *Context) Int64(name string) int64
Int64 looks up the value of a local Int64Flag, returns 0 if not found
func (cCtx *Context) Int64Slice(name string) []int64
Int64Slice looks up the value of a local Int64SliceFlag, returns nil if not
found
func (cCtx *Context) IntSlice(name string) []int
IntSlice looks up the value of a local IntSliceFlag, returns nil if not
found
func (cCtx *Context) IsSet(name string) bool
IsSet determines if the flag was actually set
func (cCtx *Context) Lineage() []*Context
Lineage returns *this* context and all of its ancestor contexts in order
from child to parent
func (cCtx *Context) LocalFlagNames() []string
LocalFlagNames returns a slice of flag names used in this context.
func (cCtx *Context) NArg() int
NArg returns the number of the command line arguments.
func (cCtx *Context) NumFlags() int
NumFlags returns the number of flags set
func (cCtx *Context) Path(name string) string
Path looks up the value of a local PathFlag, returns "" if not found
func (cCtx *Context) Set(name, value string) error
Set sets a context flag to a value.
func (cCtx *Context) String(name string) string
String looks up the value of a local StringFlag, returns "" if not found
func (cCtx *Context) StringSlice(name string) []string
StringSlice looks up the value of a local StringSliceFlag, returns nil if
not found
func (cCtx *Context) Timestamp(name string) *time.Time
Timestamp gets the timestamp from a flag name
func (cCtx *Context) Uint(name string) uint
Uint looks up the value of a local UintFlag, returns 0 if not found
func (cCtx *Context) Uint64(name string) uint64
Uint64 looks up the value of a local Uint64Flag, returns 0 if not found
func (cCtx *Context) Uint64Slice(name string) []uint64
Uint64Slice looks up the value of a local Uint64SliceFlag, returns nil if
not found
func (cCtx *Context) UintSlice(name string) []uint
UintSlice looks up the value of a local UintSliceFlag, returns nil if not
found
func (cCtx *Context) Value(name string) interface{}
Value returns the value of the flag corresponding to `name`
type Countable interface {
Count() int
}
Countable is an interface to enable detection of flag values which support
repetitive flags
type DocGenerationFlag interface {
Flag
// TakesValue returns true if the flag takes a value, otherwise false
TakesValue() bool
// GetUsage returns the usage string for the flag
GetUsage() string
// GetValue returns the flags value as string representation and an empty
// string if the flag takes no value at all.
GetValue() string
// GetDefaultText returns the default text for this flag
GetDefaultText() string
// GetEnvVars returns the env vars for this flag
GetEnvVars() []string
}
DocGenerationFlag is an interface that allows documentation generation for
the flag
type DocGenerationSliceFlag interface {
DocGenerationFlag
// IsSliceFlag returns true for flags that can be given multiple times.
IsSliceFlag() bool
}
DocGenerationSliceFlag extends DocGenerationFlag for slice-based flags.
type DurationFlag struct {
Name string
Category string
DefaultText string
FilePath string
Usage string
Required bool
Hidden bool
HasBeenSet bool
Value time.Duration
Destination *time.Duration
Aliases []string
EnvVars []string
Action func(*Context, time.Duration) error
// Has unexported fields.
}
DurationFlag is a flag with type time.Duration
func (f *DurationFlag) Apply(set *flag.FlagSet) error
Apply populates the flag given the flag set and environment
func (f *DurationFlag) Get(ctx *Context) time.Duration
Get returns the flag’s value in the given Context.
func (f *DurationFlag) GetCategory() string
GetCategory returns the category of the flag
func (f *DurationFlag) GetDefaultText() string
GetDefaultText returns the default text for this flag
func (f *DurationFlag) GetEnvVars() []string
GetEnvVars returns the env vars for this flag
func (f *DurationFlag) GetUsage() string
GetUsage returns the usage string for the flag
func (f *DurationFlag) GetValue() string
GetValue returns the flags value as string representation and an empty
string if the flag takes no value at all.
func (f *DurationFlag) IsRequired() bool
IsRequired returns whether or not the flag is required
func (f *DurationFlag) IsSet() bool
IsSet returns whether or not the flag has been set through env or file
func (f *DurationFlag) IsVisible() bool
IsVisible returns true if the flag is not hidden, otherwise false
func (f *DurationFlag) Names() []string
Names returns the names of the flag
func (f *DurationFlag) RunAction(c *Context) error
RunAction executes flag action if set
func (f *DurationFlag) String() string
String returns a readable representation of this value (for usage defaults)
func (f *DurationFlag) TakesValue() bool
TakesValue returns true if the flag takes a value, otherwise false
type ErrorFormatter interface {
Format(s fmt.State, verb rune)
}
ErrorFormatter is the interface that will suitably format the error output
type ExitCoder interface {
error
ExitCode() int
}
ExitCoder is the interface checked by `App` and `Command` for a custom exit
code
func Exit(message interface{}, exitCode int) ExitCoder
Exit wraps a message and exit code into an error, which by default is
handled with a call to os.Exit during default error handling.
This is the simplest way to trigger a non-zero exit code for an App
without having to call os.Exit manually. During testing, this behavior
can be avoided by overriding the ExitErrHandler function on an App or the
package-global OsExiter function.
func NewExitError(message interface{}, exitCode int) ExitCoder
NewExitError calls Exit to create a new ExitCoder.
Deprecated: This function is a duplicate of Exit and will eventually be
removed.
type ExitErrHandlerFunc func(cCtx *Context, err error)
ExitErrHandlerFunc is executed if provided in order to handle exitError
values returned by Actions and Before/After functions.
type Flag interface {
fmt.Stringer
// Apply Flag settings to the given flag set
Apply(*flag.FlagSet) error
// All possible names for this flag
Names() []string
// Whether the flag has been set or not
IsSet() bool
}
Flag is a common interface related to parsing flags in cli. For more
advanced flag parsing techniques, it is recommended that this interface be
implemented.
var BashCompletionFlag Flag = &BoolFlag{
Name: "generate-bash-completion",
Hidden: true,
}
BashCompletionFlag enables bash-completion for all commands and subcommands
var HelpFlag Flag = &BoolFlag{
Name: "help",
Aliases: []string{"h"},
Usage: "show help",
}
HelpFlag prints the help for all commands and subcommands. Set to nil to
disable the flag. The subcommand will still be added unless HideHelp or
HideHelpCommand is set to true.
var VersionFlag Flag = &BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "print the version",
}
VersionFlag prints the version for the application
type FlagCategories interface {
// AddFlags adds a flag to a category, creating a new category if necessary.
AddFlag(category string, fl Flag)
// VisibleCategories returns a slice of visible flag categories sorted by name
VisibleCategories() []VisibleFlagCategory
}
FlagCategories interface allows for category manipulation
type FlagEnvHintFunc func(envVars []string, str string) string
FlagEnvHintFunc is used by the default FlagStringFunc to annotate flag help
with the environment variable details.
var FlagEnvHinter FlagEnvHintFunc = withEnvHint
FlagEnvHinter annotates flag help message with the environment variable
details. This is used by the default FlagStringer.
type FlagFileHintFunc func(filePath, str string) string
FlagFileHintFunc is used by the default FlagStringFunc to annotate flag help
with the file path details.
var FlagFileHinter FlagFileHintFunc = withFileHint
FlagFileHinter annotates flag help message with the environment variable
details. This is used by the default FlagStringer.
type FlagNamePrefixFunc func(fullName []string, placeholder string) string
FlagNamePrefixFunc is used by the default FlagStringFunc to create prefix
text for a flag's full name.
var FlagNamePrefixer FlagNamePrefixFunc = prefixedNames
FlagNamePrefixer converts a full flag name and its placeholder into the help
message flag prefix. This is used by the default FlagStringer.
type FlagStringFunc func(Flag) string
FlagStringFunc is used by the help generation to display a flag, which is
expected to be a single line.
var FlagStringer FlagStringFunc = stringifyFlag
FlagStringer converts a flag definition to a string. This is used by help to
display a flag.
type FlagsByName []Flag
FlagsByName is a slice of Flag.
func (f FlagsByName) Len() int
func (f FlagsByName) Less(i, j int) bool
func (f FlagsByName) Swap(i, j int)
type Float64Flag struct {
Name string
Category string
DefaultText string
FilePath string
Usage string
Required bool
Hidden bool
HasBeenSet bool
Value float64
Destination *float64
Aliases []string
EnvVars []string
Action func(*Context, float64) error
// Has unexported fields.
}
Float64Flag is a flag with type float64
func (f *Float64Flag) Apply(set *flag.FlagSet) error
Apply populates the flag given the flag set and environment
func (f *Float64Flag) Get(ctx *Context) float64
Get returns the flag’s value in the given Context.
func (f *Float64Flag) GetCategory() string
GetCategory returns the category of the flag
func (f *Float64Flag) GetDefaultText() string
GetDefaultText returns the default text for this flag
func (f *Float64Flag) GetEnvVars() []string
GetEnvVars returns the env vars for this flag
func (f *Float64Flag) GetUsage() string
GetUsage returns the usage string for the flag
func (f *Float64Flag) GetValue() string
GetValue returns the flags value as string representation and an empty
string if the flag takes no value at all.
func (f *Float64Flag) IsRequired() bool
IsRequired returns whether or not the flag is required
func (f *Float64Flag) IsSet() bool