1package cli // import "github.com/urfave/cli/v2"
2
3Package cli provides a minimal framework for creating and organizing command
4line Go applications. cli is designed to be easy to understand and write,
5the most simple cli application can be written as follows:
6
7 func main() {
8 (&cli.App{}).Run(os.Args)
9 }
10
11Of course this application does not do much, so let's make this an actual
12application:
13
14 func main() {
15 app := &cli.App{
16 Name: "greet",
17 Usage: "say a greeting",
18 Action: func(c *cli.Context) error {
19 fmt.Println("Greetings")
20 return nil
21 },
22 }
23
24 app.Run(os.Args)
25 }
26
27VARIABLES
28
29var (
30 SuggestFlag SuggestFlagFunc = nil // initialized in suggestions.go unless built with urfave_cli_no_suggest
31 SuggestCommand SuggestCommandFunc = nil // initialized in suggestions.go unless built with urfave_cli_no_suggest
32 SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
33)
34var AppHelpTemplate = `NAME:
35 {{template "helpNameTemplate" .}}
36
37USAGE:
38 {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}}
39
40VERSION:
41 {{.Version}}{{end}}{{end}}{{if .Description}}
42
43DESCRIPTION:
44 {{template "descriptionTemplate" .}}{{end}}
45{{- if len .Authors}}
46
47AUTHOR{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}}
48
49COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
50
51GLOBAL OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
52
53GLOBAL OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}}
54
55COPYRIGHT:
56 {{template "copyrightTemplate" .}}{{end}}
57`
58 AppHelpTemplate is the text template for the Default help topic. cli.go
59 uses text/template to render templates. You can render custom help text by
60 setting this variable.
61
62var CommandHelpTemplate = `NAME:
63 {{template "helpNameTemplate" .}}
64
65USAGE:
66 {{template "usageTemplate" .}}{{if .Category}}
67
68CATEGORY:
69 {{.Category}}{{end}}{{if .Description}}
70
71DESCRIPTION:
72 {{template "descriptionTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
73
74OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
75
76OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
77`
78 CommandHelpTemplate is the text template for the command help topic. cli.go
79 uses text/template to render templates. You can render custom help text by
80 setting this variable.
81
82var ErrWriter io.Writer = os.Stderr
83 ErrWriter is used to write errors to the user. This can be anything
84 implementing the io.Writer interface and defaults to os.Stderr.
85
86var FishCompletionTemplate = `# {{ .App.Name }} fish shell completion
87
88function __fish_{{ .App.Name }}_no_subcommand --description 'Test if there has been any subcommand yet'
89 for i in (commandline -opc)
90 if contains -- $i{{ range $v := .AllCommands }} {{ $v }}{{ end }}
91 return 1
92 end
93 end
94 return 0
95end
96
97{{ range $v := .Completions }}{{ $v }}
98{{ end }}`
99var MarkdownDocTemplate = `{{if gt .SectionNum 0}}% {{ .App.Name }} {{ .SectionNum }}
100
101{{end}}# NAME
102
103{{ .App.Name }}{{ if .App.Usage }} - {{ .App.Usage }}{{ end }}
104
105# SYNOPSIS
106
107{{ .App.Name }}
108{{ if .SynopsisArgs }}
109` + "```" + `
110{{ range $v := .SynopsisArgs }}{{ $v }}{{ end }}` + "```" + `
111{{ end }}{{ if .App.Description }}
112# DESCRIPTION
113
114{{ .App.Description }}
115{{ end }}
116**Usage**:
117
118` + "```" + `{{ if .App.UsageText }}
119{{ .App.UsageText }}
120{{ else }}
121{{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
122{{ end }}` + "```" + `
123{{ if .GlobalArgs }}
124# GLOBAL OPTIONS
125{{ range $v := .GlobalArgs }}
126{{ $v }}{{ end }}
127{{ end }}{{ if .Commands }}
128# COMMANDS
129{{ range $v := .Commands }}
130{{ $v }}{{ end }}{{ end }}`
131var OsExiter = os.Exit
132 OsExiter is the function used when the app exits. If not set defaults to
133 os.Exit.
134
135var SubcommandHelpTemplate = `NAME:
136 {{template "helpNameTemplate" .}}
137
138USAGE:
139 {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.HelpName}} {{if .VisibleFlags}}command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}{{if .Args}}[arguments...]{{end}}{{end}}{{end}}{{if .Description}}
140
141DESCRIPTION:
142 {{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}}
143
144COMMANDS:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
145
146OPTIONS:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
147
148OPTIONS:{{template "visibleFlagTemplate" .}}{{end}}
149`
150 SubcommandHelpTemplate is the text template for the subcommand help topic.
151 cli.go uses text/template to render templates. You can render custom help
152 text by setting this variable.
153
154var VersionPrinter = printVersion
155 VersionPrinter prints the version for the App
156
157var HelpPrinter helpPrinter = printHelp
158 HelpPrinter is a function that writes the help output. If not set
159 explicitly, this calls HelpPrinterCustom using only the default template
160 functions.
161
162 If custom logic for printing help is required, this function can be
163 overridden. If the ExtraInfo field is defined on an App, this function
164 should not be modified, as HelpPrinterCustom will be used directly in order
165 to capture the extra information.
166
167var HelpPrinterCustom helpPrinterCustom = printHelpCustom
168 HelpPrinterCustom is a function that writes the help output. It is used as
169 the default implementation of HelpPrinter, and may be called directly if the
170 ExtraInfo field is set on an App.
171
172 In the default implementation, if the customFuncs argument contains a
173 "wrapAt" key, which is a function which takes no arguments and returns an
174 int, this int value will be used to produce a "wrap" function used by the
175 default template to wrap long lines.
176
177
178FUNCTIONS
179
180func DefaultAppComplete(cCtx *Context)
181 DefaultAppComplete prints the list of subcommands as the default app
182 completion method
183
184func DefaultCompleteWithFlags(cmd *Command) func(cCtx *Context)
185func FlagNames(name string, aliases []string) []string
186func HandleAction(action interface{}, cCtx *Context) (err error)
187 HandleAction attempts to figure out which Action signature was used.
188 If it's an ActionFunc or a func with the legacy signature for Action,
189 the func is run!
190
191func HandleExitCoder(err error)
192 HandleExitCoder handles errors implementing ExitCoder by printing their
193 message and calling OsExiter with the given exit code.
194
195 If the given error instead implements MultiError, each error will be checked
196 for the ExitCoder interface, and OsExiter will be called with the last exit
197 code found, or exit code 1 if no ExitCoder is found.
198
199 This function is the default error-handling behavior for an App.
200
201func ShowAppHelp(cCtx *Context) error
202 ShowAppHelp is an action that displays the help.
203
204func ShowAppHelpAndExit(c *Context, exitCode int)
205 ShowAppHelpAndExit - Prints the list of subcommands for the app and exits
206 with exit code.
207
208func ShowCommandCompletions(ctx *Context, command string)
209 ShowCommandCompletions prints the custom completions for a given command
210
211func ShowCommandHelp(ctx *Context, command string) error
212 ShowCommandHelp prints help for the given command
213
214func ShowCommandHelpAndExit(c *Context, command string, code int)
215 ShowCommandHelpAndExit - exits with code after showing help
216
217func ShowCompletions(cCtx *Context)
218 ShowCompletions prints the lists of commands within a given context
219
220func ShowSubcommandHelp(cCtx *Context) error
221 ShowSubcommandHelp prints help for the given subcommand
222
223func ShowSubcommandHelpAndExit(c *Context, exitCode int)
224 ShowSubcommandHelpAndExit - Prints help for the given subcommand and exits
225 with exit code.
226
227func ShowVersion(cCtx *Context)
228 ShowVersion prints the version number of the App
229
230
231TYPES
232
233type ActionFunc func(*Context) error
234 ActionFunc is the action to execute when no subcommands are specified
235
236type ActionableFlag interface {
237 Flag
238 RunAction(*Context) error
239}
240 ActionableFlag is an interface that wraps Flag interface and RunAction
241 operation.
242
243type AfterFunc func(*Context) error
244 AfterFunc is an action to execute after any subcommands are run, but after
245 the subcommand has finished it is run even if Action() panics
246
247type App struct {
248 // The name of the program. Defaults to path.Base(os.Args[0])
249 Name string
250 // Full name of command for help, defaults to Name
251 HelpName string
252 // Description of the program.
253 Usage string
254 // Text to override the USAGE section of help
255 UsageText string
256 // Whether this command supports arguments
257 Args bool
258 // Description of the program argument format.
259 ArgsUsage string
260 // Version of the program
261 Version string
262 // Description of the program
263 Description string
264 // DefaultCommand is the (optional) name of a command
265 // to run if no command names are passed as CLI arguments.
266 DefaultCommand string
267 // List of commands to execute
268 Commands []*Command
269 // List of flags to parse
270 Flags []Flag
271 // Boolean to enable bash completion commands
272 EnableBashCompletion bool
273 // Boolean to hide built-in help command and help flag
274 HideHelp bool
275 // Boolean to hide built-in help command but keep help flag.
276 // Ignored if HideHelp is true.
277 HideHelpCommand bool
278 // Boolean to hide built-in version flag and the VERSION section of help
279 HideVersion bool
280
281 // An action to execute when the shell completion flag is set
282 BashComplete BashCompleteFunc
283 // An action to execute before any subcommands are run, but after the context is ready
284 // If a non-nil error is returned, no subcommands are run
285 Before BeforeFunc
286 // An action to execute after any subcommands are run, but after the subcommand has finished
287 // It is run even if Action() panics
288 After AfterFunc
289 // The action to execute when no subcommands are specified
290 Action ActionFunc
291 // Execute this function if the proper command cannot be found
292 CommandNotFound CommandNotFoundFunc
293 // Execute this function if a usage error occurs
294 OnUsageError OnUsageErrorFunc
295 // Execute this function when an invalid flag is accessed from the context
296 InvalidFlagAccessHandler InvalidFlagAccessFunc
297 // Compilation date
298 Compiled time.Time
299 // List of all authors who contributed
300 Authors []*Author
301 // Copyright of the binary if any
302 Copyright string
303 // Reader reader to write input to (useful for tests)
304 Reader io.Reader
305 // Writer writer to write output to
306 Writer io.Writer
307 // ErrWriter writes error output
308 ErrWriter io.Writer
309 // ExitErrHandler processes any error encountered while running an App before
310 // it is returned to the caller. If no function is provided, HandleExitCoder
311 // is used as the default behavior.
312 ExitErrHandler ExitErrHandlerFunc
313 // Other custom info
314 Metadata map[string]interface{}
315 // Carries a function which returns app specific info.
316 ExtraInfo func() map[string]string
317 // CustomAppHelpTemplate the text template for app help topic.
318 // cli.go uses text/template to render templates. You can
319 // render custom help text by setting this variable.
320 CustomAppHelpTemplate string
321 // SliceFlagSeparator is used to customize the separator for SliceFlag, the default is ","
322 SliceFlagSeparator string
323 // DisableSliceFlagSeparator is used to disable SliceFlagSeparator, the default is false
324 DisableSliceFlagSeparator bool
325 // Boolean to enable short-option handling so user can combine several
326 // single-character bool arguments into one
327 // i.e. foobar -o -v -> foobar -ov
328 UseShortOptionHandling bool
329 // Enable suggestions for commands and flags
330 Suggest bool
331 // Allows global flags set by libraries which use flag.XXXVar(...) directly
332 // to be parsed through this library
333 AllowExtFlags bool
334 // Treat all flags as normal arguments if true
335 SkipFlagParsing bool
336
337 // Has unexported fields.
338}
339 App is the main structure of a cli application. It is recommended that an
340 app be created with the cli.NewApp() function
341
342func NewApp() *App
343 NewApp creates a new cli Application with some reasonable defaults for Name,
344 Usage, Version and Action.
345
346func (a *App) Command(name string) *Command
347 Command returns the named command on App. Returns nil if the command does
348 not exist
349
350func (a *App) Run(arguments []string) (err error)
351 Run is the entry point to the cli app. Parses the arguments slice and routes
352 to the proper flag/args combination
353
354func (a *App) RunAndExitOnError()
355 RunAndExitOnError calls .Run() and exits non-zero if an error was returned
356
357 Deprecated: instead you should return an error that fulfills cli.ExitCoder
358 to cli.App.Run. This will cause the application to exit with the given error
359 code in the cli.ExitCoder
360
361func (a *App) RunAsSubcommand(ctx *Context) (err error)
362 RunAsSubcommand is for legacy/compatibility purposes only. New code should
363 only use App.RunContext. This function is slated to be removed in v3.
364
365func (a *App) RunContext(ctx context.Context, arguments []string) (err error)
366 RunContext is like Run except it takes a Context that will be passed to
367 its commands and sub-commands. Through this, you can propagate timeouts and
368 cancellation requests
369
370func (a *App) Setup()
371 Setup runs initialization code to ensure all data structures are ready
372 for `Run` or inspection prior to `Run`. It is internally called by `Run`,
373 but will return early if setup has already happened.
374
375func (a *App) ToFishCompletion() (string, error)
376 ToFishCompletion creates a fish completion string for the `*App` The
377 function errors if either parsing or writing of the string fails.
378
379func (a *App) ToMan() (string, error)
380 ToMan creates a man page string for the `*App` The function errors if either
381 parsing or writing of the string fails.
382
383func (a *App) ToManWithSection(sectionNumber int) (string, error)
384 ToMan creates a man page string with section number for the `*App` The
385 function errors if either parsing or writing of the string fails.
386
387func (a *App) ToMarkdown() (string, error)
388 ToMarkdown creates a markdown string for the `*App` The function errors if
389 either parsing or writing of the string fails.
390
391func (a *App) VisibleCategories() []CommandCategory
392 VisibleCategories returns a slice of categories and commands that are
393 Hidden=false
394
395func (a *App) VisibleCommands() []*Command
396 VisibleCommands returns a slice of the Commands with Hidden=false
397
398func (a *App) VisibleFlagCategories() []VisibleFlagCategory
399 VisibleFlagCategories returns a slice containing all the categories with the
400 flags they contain
401
402func (a *App) VisibleFlags() []Flag
403 VisibleFlags returns a slice of the Flags with Hidden=false
404
405type Args interface {
406 // Get returns the nth argument, or else a blank string
407 Get(n int) string
408 // First returns the first argument, or else a blank string
409 First() string
410 // Tail returns the rest of the arguments (not the first one)
411 // or else an empty string slice
412 Tail() []string
413 // Len returns the length of the wrapped slice
414 Len() int
415 // Present checks if there are any arguments present
416 Present() bool
417 // Slice returns a copy of the internal slice
418 Slice() []string
419}
420
421type Author struct {
422 Name string // The Authors name
423 Email string // The Authors email
424}
425 Author represents someone who has contributed to a cli project.
426
427func (a *Author) String() string
428 String makes Author comply to the Stringer interface, to allow an easy print
429 in the templating process
430
431type BashCompleteFunc func(*Context)
432 BashCompleteFunc is an action to execute when the shell completion flag is
433 set
434
435type BeforeFunc func(*Context) error
436 BeforeFunc is an action to execute before any subcommands are run, but after
437 the context is ready if a non-nil error is returned, no subcommands are run
438
439type BoolFlag struct {
440 Name string
441
442 Category string
443 DefaultText string
444 FilePath string
445 Usage string
446
447 Required bool
448 Hidden bool
449 HasBeenSet bool
450
451 Value bool
452 Destination *bool
453
454 Aliases []string
455 EnvVars []string
456
457 Count *int
458
459 DisableDefaultText bool
460
461 Action func(*Context, bool) error
462 // Has unexported fields.
463}
464 BoolFlag is a flag with type bool
465
466func (f *BoolFlag) Apply(set *flag.FlagSet) error
467 Apply populates the flag given the flag set and environment
468
469func (f *BoolFlag) Get(ctx *Context) bool
470 Get returns the flag’s value in the given Context.
471
472func (f *BoolFlag) GetCategory() string
473 GetCategory returns the category for the flag
474
475func (f *BoolFlag) GetDefaultText() string
476 GetDefaultText returns the default text for this flag
477
478func (f *BoolFlag) GetEnvVars() []string
479 GetEnvVars returns the env vars for this flag
480
481func (f *BoolFlag) GetUsage() string
482 GetUsage returns the usage string for the flag
483
484func (f *BoolFlag) GetValue() string
485 GetValue returns the flags value as string representation and an empty
486 string if the flag takes no value at all.
487
488func (f *BoolFlag) IsRequired() bool
489 IsRequired returns whether or not the flag is required
490
491func (f *BoolFlag) IsSet() bool
492 IsSet returns whether or not the flag has been set through env or file
493
494func (f *BoolFlag) IsVisible() bool
495 IsVisible returns true if the flag is not hidden, otherwise false
496
497func (f *BoolFlag) Names() []string
498 Names returns the names of the flag
499
500func (f *BoolFlag) RunAction(c *Context) error
501 RunAction executes flag action if set
502
503func (f *BoolFlag) String() string
504 String returns a readable representation of this value (for usage defaults)
505
506func (f *BoolFlag) TakesValue() bool
507 TakesValue returns true of the flag takes a value, otherwise false
508
509type CategorizableFlag interface {
510 VisibleFlag
511
512 GetCategory() string
513}
514 CategorizableFlag is an interface that allows us to potentially use a flag
515 in a categorized representation.
516
517type Command struct {
518 // The name of the command
519 Name string
520 // A list of aliases for the command
521 Aliases []string
522 // A short description of the usage of this command
523 Usage string
524 // Custom text to show on USAGE section of help
525 UsageText string
526 // A longer explanation of how the command works
527 Description string
528 // Whether this command supports arguments
529 Args bool
530 // A short description of the arguments of this command
531 ArgsUsage string
532 // The category the command is part of
533 Category string
534 // The function to call when checking for bash command completions
535 BashComplete BashCompleteFunc
536 // An action to execute before any sub-subcommands are run, but after the context is ready
537 // If a non-nil error is returned, no sub-subcommands are run
538 Before BeforeFunc
539 // An action to execute after any subcommands are run, but after the subcommand has finished
540 // It is run even if Action() panics
541 After AfterFunc
542 // The function to call when this command is invoked
543 Action ActionFunc
544 // Execute this function if a usage error occurs.
545 OnUsageError OnUsageErrorFunc
546 // List of child commands
547 Subcommands []*Command
548 // List of flags to parse
549 Flags []Flag
550
551 // Treat all flags as normal arguments if true
552 SkipFlagParsing bool
553 // Boolean to hide built-in help command and help flag
554 HideHelp bool
555 // Boolean to hide built-in help command but keep help flag
556 // Ignored if HideHelp is true.
557 HideHelpCommand bool
558 // Boolean to hide this command from help or completion
559 Hidden bool
560 // Boolean to enable short-option handling so user can combine several
561 // single-character bool arguments into one
562 // i.e. foobar -o -v -> foobar -ov
563 UseShortOptionHandling bool
564
565 // Full name of command for help, defaults to full command name, including parent commands.
566 HelpName string
567
568 // CustomHelpTemplate the text template for the command help topic.
569 // cli.go uses text/template to render templates. You can
570 // render custom help text by setting this variable.
571 CustomHelpTemplate string
572
573 // Has unexported fields.
574}
575 Command is a subcommand for a cli.App.
576
577func (cmd *Command) Command(name string) *Command
578
579func (c *Command) FullName() string
580 FullName returns the full name of the command. For subcommands this ensures
581 that parent commands are part of the command path
582
583func (c *Command) HasName(name string) bool
584 HasName returns true if Command.Name matches given name
585
586func (c *Command) Names() []string
587 Names returns the names including short names and aliases.
588
589func (c *Command) Run(cCtx *Context, arguments ...string) (err error)
590
591func (c *Command) VisibleCategories() []CommandCategory
592 VisibleCategories returns a slice of categories and commands that are
593 Hidden=false
594
595func (c *Command) VisibleCommands() []*Command
596 VisibleCommands returns a slice of the Commands with Hidden=false
597
598func (c *Command) VisibleFlagCategories() []VisibleFlagCategory
599 VisibleFlagCategories returns a slice containing all the visible flag
600 categories with the flags they contain
601
602func (c *Command) VisibleFlags() []Flag
603 VisibleFlags returns a slice of the Flags with Hidden=false
604
605type CommandCategories interface {
606 // AddCommand adds a command to a category, creating a new category if necessary.
607 AddCommand(category string, command *Command)
608 // Categories returns a slice of categories sorted by name
609 Categories() []CommandCategory
610}
611 CommandCategories interface allows for category manipulation
612
613type CommandCategory interface {
614 // Name returns the category name string
615 Name() string
616 // VisibleCommands returns a slice of the Commands with Hidden=false
617 VisibleCommands() []*Command
618}
619 CommandCategory is a category containing commands.
620
621type CommandNotFoundFunc func(*Context, string)
622 CommandNotFoundFunc is executed if the proper command cannot be found
623
624type Commands []*Command
625
626type CommandsByName []*Command
627
628func (c CommandsByName) Len() int
629
630func (c CommandsByName) Less(i, j int) bool
631
632func (c CommandsByName) Swap(i, j int)
633
634type Context struct {
635 context.Context
636 App *App
637 Command *Command
638
639 // Has unexported fields.
640}
641 Context is a type that is passed through to each Handler action in a cli
642 application. Context can be used to retrieve context-specific args and
643 parsed command-line options.
644
645func NewContext(app *App, set *flag.FlagSet, parentCtx *Context) *Context
646 NewContext creates a new context. For use in when invoking an App or Command
647 action.
648
649func (cCtx *Context) Args() Args
650 Args returns the command line arguments associated with the context.
651
652func (cCtx *Context) Bool(name string) bool
653 Bool looks up the value of a local BoolFlag, returns false if not found
654
655func (cCtx *Context) Count(name string) int
656 Count returns the num of occurrences of this flag
657
658func (cCtx *Context) Duration(name string) time.Duration
659 Duration looks up the value of a local DurationFlag, returns 0 if not found
660
661func (cCtx *Context) FlagNames() []string
662 FlagNames returns a slice of flag names used by the this context and all of
663 its parent contexts.
664
665func (cCtx *Context) Float64(name string) float64
666 Float64 looks up the value of a local Float64Flag, returns 0 if not found
667
668func (cCtx *Context) Float64Slice(name string) []float64
669 Float64Slice looks up the value of a local Float64SliceFlag, returns nil if
670 not found
671
672func (cCtx *Context) Generic(name string) interface{}
673 Generic looks up the value of a local GenericFlag, returns nil if not found
674
675func (cCtx *Context) Int(name string) int
676 Int looks up the value of a local IntFlag, returns 0 if not found
677
678func (cCtx *Context) Int64(name string) int64
679 Int64 looks up the value of a local Int64Flag, returns 0 if not found
680
681func (cCtx *Context) Int64Slice(name string) []int64
682 Int64Slice looks up the value of a local Int64SliceFlag, returns nil if not
683 found
684
685func (cCtx *Context) IntSlice(name string) []int
686 IntSlice looks up the value of a local IntSliceFlag, returns nil if not
687 found
688
689func (cCtx *Context) IsSet(name string) bool
690 IsSet determines if the flag was actually set
691
692func (cCtx *Context) Lineage() []*Context
693 Lineage returns *this* context and all of its ancestor contexts in order
694 from child to parent
695
696func (cCtx *Context) LocalFlagNames() []string
697 LocalFlagNames returns a slice of flag names used in this context.
698
699func (cCtx *Context) NArg() int
700 NArg returns the number of the command line arguments.
701
702func (cCtx *Context) NumFlags() int
703 NumFlags returns the number of flags set
704
705func (cCtx *Context) Path(name string) string
706 Path looks up the value of a local PathFlag, returns "" if not found
707
708func (cCtx *Context) Set(name, value string) error
709 Set sets a context flag to a value.
710
711func (cCtx *Context) String(name string) string
712 String looks up the value of a local StringFlag, returns "" if not found
713
714func (cCtx *Context) StringSlice(name string) []string
715 StringSlice looks up the value of a local StringSliceFlag, returns nil if
716 not found
717
718func (cCtx *Context) Timestamp(name string) *time.Time
719 Timestamp gets the timestamp from a flag name
720
721func (cCtx *Context) Uint(name string) uint
722 Uint looks up the value of a local UintFlag, returns 0 if not found
723
724func (cCtx *Context) Uint64(name string) uint64
725 Uint64 looks up the value of a local Uint64Flag, returns 0 if not found
726
727func (cCtx *Context) Uint64Slice(name string) []uint64
728 Uint64Slice looks up the value of a local Uint64SliceFlag, returns nil if
729 not found
730
731func (cCtx *Context) UintSlice(name string) []uint
732 UintSlice looks up the value of a local UintSliceFlag, returns nil if not
733 found
734
735func (cCtx *Context) Value(name string) interface{}
736 Value returns the value of the flag corresponding to `name`
737
738type Countable interface {
739 Count() int
740}
741 Countable is an interface to enable detection of flag values which support
742 repetitive flags
743
744type DocGenerationFlag interface {
745 Flag
746
747 // TakesValue returns true if the flag takes a value, otherwise false
748 TakesValue() bool
749
750 // GetUsage returns the usage string for the flag
751 GetUsage() string
752
753 // GetValue returns the flags value as string representation and an empty
754 // string if the flag takes no value at all.
755 GetValue() string
756
757 // GetDefaultText returns the default text for this flag
758 GetDefaultText() string
759
760 // GetEnvVars returns the env vars for this flag
761 GetEnvVars() []string
762}
763 DocGenerationFlag is an interface that allows documentation generation for
764 the flag
765
766type DocGenerationSliceFlag interface {
767 DocGenerationFlag
768
769 // IsSliceFlag returns true for flags that can be given multiple times.
770 IsSliceFlag() bool
771}
772 DocGenerationSliceFlag extends DocGenerationFlag for slice-based flags.
773
774type DurationFlag struct {
775 Name string
776
777 Category string
778 DefaultText string
779 FilePath string
780 Usage string
781
782 Required bool
783 Hidden bool
784 HasBeenSet bool
785
786 Value time.Duration
787 Destination *time.Duration
788
789 Aliases []string
790 EnvVars []string
791
792 Action func(*Context, time.Duration) error
793 // Has unexported fields.
794}
795 DurationFlag is a flag with type time.Duration
796
797func (f *DurationFlag) Apply(set *flag.FlagSet) error
798 Apply populates the flag given the flag set and environment
799
800func (f *DurationFlag) Get(ctx *Context) time.Duration
801 Get returns the flag’s value in the given Context.
802
803func (f *DurationFlag) GetCategory() string
804 GetCategory returns the category for the flag
805
806func (f *DurationFlag) GetDefaultText() string
807 GetDefaultText returns the default text for this flag
808
809func (f *DurationFlag) GetEnvVars() []string
810 GetEnvVars returns the env vars for this flag
811
812func (f *DurationFlag) GetUsage() string
813 GetUsage returns the usage string for the flag
814
815func (f *DurationFlag) GetValue() string
816 GetValue returns the flags value as string representation and an empty
817 string if the flag takes no value at all.
818
819func (f *DurationFlag) IsRequired() bool
820 IsRequired returns whether or not the flag is required
821
822func (f *DurationFlag) IsSet() bool
823 IsSet returns whether or not the flag has been set through env or file
824
825func (f *DurationFlag) IsVisible() bool
826 IsVisible returns true if the flag is not hidden, otherwise false
827
828func (f *DurationFlag) Names() []string
829 Names returns the names of the flag
830
831func (f *DurationFlag) RunAction(c *Context) error
832 RunAction executes flag action if set
833
834func (f *DurationFlag) String() string
835 String returns a readable representation of this value (for usage defaults)
836
837func (f *DurationFlag) TakesValue() bool
838 TakesValue returns true of the flag takes a value, otherwise false
839
840type ErrorFormatter interface {
841 Format(s fmt.State, verb rune)
842}
843 ErrorFormatter is the interface that will suitably format the error output
844
845type ExitCoder interface {
846 error
847 ExitCode() int
848}
849 ExitCoder is the interface checked by `App` and `Command` for a custom exit
850 code
851
852func Exit(message interface{}, exitCode int) ExitCoder
853 Exit wraps a message and exit code into an error, which by default is
854 handled with a call to os.Exit during default error handling.
855
856 This is the simplest way to trigger a non-zero exit code for an App
857 without having to call os.Exit manually. During testing, this behavior
858 can be avoided by overriding the ExitErrHandler function on an App or the
859 package-global OsExiter function.
860
861func NewExitError(message interface{}, exitCode int) ExitCoder
862 NewExitError calls Exit to create a new ExitCoder.
863
864 Deprecated: This function is a duplicate of Exit and will eventually be
865 removed.
866
867type ExitErrHandlerFunc func(cCtx *Context, err error)
868 ExitErrHandlerFunc is executed if provided in order to handle exitError
869 values returned by Actions and Before/After functions.
870
871type Flag interface {
872 fmt.Stringer
873 // Apply Flag settings to the given flag set
874 Apply(*flag.FlagSet) error
875 Names() []string
876 IsSet() bool
877}
878 Flag is a common interface related to parsing flags in cli. For more
879 advanced flag parsing techniques, it is recommended that this interface be
880 implemented.
881
882var BashCompletionFlag Flag = &BoolFlag{
883 Name: "generate-bash-completion",
884 Hidden: true,
885}
886 BashCompletionFlag enables bash-completion for all commands and subcommands
887
888var HelpFlag Flag = &BoolFlag{
889 Name: "help",
890 Aliases: []string{"h"},
891 Usage: "show help",
892 DisableDefaultText: true,
893}
894 HelpFlag prints the help for all commands and subcommands. Set to nil to
895 disable the flag. The subcommand will still be added unless HideHelp or
896 HideHelpCommand is set to true.
897
898var VersionFlag Flag = &BoolFlag{
899 Name: "version",
900 Aliases: []string{"v"},
901 Usage: "print the version",
902 DisableDefaultText: true,
903}
904 VersionFlag prints the version for the application
905
906type FlagCategories interface {
907 // AddFlags adds a flag to a category, creating a new category if necessary.
908 AddFlag(category string, fl Flag)
909 // VisibleCategories returns a slice of visible flag categories sorted by name
910 VisibleCategories() []VisibleFlagCategory
911}
912 FlagCategories interface allows for category manipulation
913
914type FlagEnvHintFunc func(envVars []string, str string) string
915 FlagEnvHintFunc is used by the default FlagStringFunc to annotate flag help
916 with the environment variable details.
917
918var FlagEnvHinter FlagEnvHintFunc = withEnvHint
919 FlagEnvHinter annotates flag help message with the environment variable
920 details. This is used by the default FlagStringer.
921
922type FlagFileHintFunc func(filePath, str string) string
923 FlagFileHintFunc is used by the default FlagStringFunc to annotate flag help
924 with the file path details.
925
926var FlagFileHinter FlagFileHintFunc = withFileHint
927 FlagFileHinter annotates flag help message with the environment variable
928 details. This is used by the default FlagStringer.
929
930type FlagNamePrefixFunc func(fullName []string, placeholder string) string
931 FlagNamePrefixFunc is used by the default FlagStringFunc to create prefix
932 text for a flag's full name.
933
934var FlagNamePrefixer FlagNamePrefixFunc = prefixedNames
935 FlagNamePrefixer converts a full flag name and its placeholder into the help
936 message flag prefix. This is used by the default FlagStringer.
937
938type FlagStringFunc func(Flag) string
939 FlagStringFunc is used by the help generation to display a flag, which is
940 expected to be a single line.
941
942var FlagStringer FlagStringFunc = stringifyFlag
943 FlagStringer converts a flag definition to a string. This is used by help to
944 display a flag.
945
946type FlagsByName []Flag
947 FlagsByName is a slice of Flag.
948
949func (f FlagsByName) Len() int
950
951func (f FlagsByName) Less(i, j int) bool
952
953func (f FlagsByName) Swap(i, j int)
954
955type Float64Flag struct {
956 Name string
957
958 Category string
959 DefaultText string
960 FilePath string
961 Usage string
962
963 Required bool
964 Hidden bool
965 HasBeenSet bool
966
967 Value float64
968 Destination *float64
969
970 Aliases []string
971 EnvVars []string
972
973 Action func(*Context, float64) error
974 // Has unexported fields.
975}
976 Float64Flag is a flag with type float64
977
978func (f *Float64Flag) Apply(set *flag.FlagSet) error
979 Apply populates the flag given the flag set and environment
980
981func (f *Float64Flag) Get(ctx *Context) float64
982 Get returns the flag’s value in the given Context.
983
984func (f *Float64Flag) GetCategory() string
985 GetCategory returns the category for the flag
986
987func (f *Float64Flag) GetDefaultText() string
988 GetDefaultText returns the default text for this flag
989
990func (f *Float64Flag) GetEnvVars() []string
991 GetEnvVars returns the env vars for this flag
992
993func (f *Float64Flag) GetUsage() string
994 GetUsage returns the usage string for the flag
995
996func (f *Float64Flag) GetValue() string
997 GetValue returns the flags value as string representation and an empty
998 string if the flag takes no value at all.
999
1000func (f *Float64Flag) IsRequired() bool
1001 IsRequired returns whether or not the flag is required
1002
1003func (f *Float64Flag) IsSet() bool
1004 IsSet returns whether or not the flag has been set through env or file
1005
1006func (f *Float64Flag) IsVisible() bool
1007 IsVisible returns true if the flag is not hidden, otherwise false
1008
1009func (f *Float64Flag) Names() []string
1010 Names returns the names of the flag
1011
1012func (f *Float64Flag) RunAction(c *Context) error
1013 RunAction executes flag action if set
1014
1015func (f *Float64Flag) String() string
1016 String returns a readable representation of this value (for usage defaults)
1017
1018func (f *Float64Flag) TakesValue() bool
1019 TakesValue returns true of the flag takes a value, otherwise false
1020
1021type Float64Slice struct {
1022 // Has unexported fields.
1023}
1024 Float64Slice wraps []float64 to satisfy flag.Value
1025
1026func NewFloat64Slice(defaults ...float64) *Float64Slice
1027 NewFloat64Slice makes a *Float64Slice with default values
1028
1029func (f *Float64Slice) Get() interface{}
1030 Get returns the slice of float64s set by this flag
1031
1032func (f *Float64Slice) Serialize() string
1033 Serialize allows Float64Slice to fulfill Serializer
1034
1035func (f *Float64Slice) Set(value string) error
1036 Set parses the value into a float64 and appends it to the list of values
1037
1038func (f *Float64Slice) String() string
1039 String returns a readable representation of this value (for usage defaults)
1040
1041func (f *Float64Slice) Value() []float64
1042 Value returns the slice of float64s set by this flag
1043
1044func (f *Float64Slice) WithSeparatorSpec(spec separatorSpec)
1045
1046type Float64SliceFlag struct {
1047 Name string
1048
1049 Category string
1050 DefaultText string
1051 FilePath string
1052 Usage string
1053
1054 Required bool
1055 Hidden bool
1056 HasBeenSet bool
1057
1058 Value *Float64Slice
1059 Destination *Float64Slice
1060
1061 Aliases []string
1062 EnvVars []string
1063
1064 Action func(*Context, []float64) error
1065 // Has unexported fields.
1066}
1067 Float64SliceFlag is a flag with type *Float64Slice
1068
1069func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error
1070 Apply populates the flag given the flag set and environment
1071
1072func (f *Float64SliceFlag) Get(ctx *Context) []float64
1073 Get returns the flag’s value in the given Context.
1074
1075func (f *Float64SliceFlag) GetCategory() string
1076 GetCategory returns the category for the flag
1077
1078func (f *Float64SliceFlag) GetDefaultText() string
1079 GetDefaultText returns the default text for this flag
1080
1081func (f *Float64SliceFlag) GetDestination() []float64
1082
1083func (f *Float64SliceFlag) GetEnvVars() []string
1084 GetEnvVars returns the env vars for this flag
1085
1086func (f *Float64SliceFlag) GetUsage() string
1087 GetUsage returns the usage string for the flag
1088
1089func (f *Float64SliceFlag) GetValue() string
1090 GetValue returns the flags value as string representation and an empty
1091 string if the flag takes no value at all.
1092
1093func (f *Float64SliceFlag) IsRequired() bool
1094 IsRequired returns whether or not the flag is required
1095
1096func (f *Float64SliceFlag) IsSet() bool
1097 IsSet returns whether or not the flag has been set through env or file
1098
1099func (f *Float64SliceFlag) IsSliceFlag() bool
1100 IsSliceFlag implements DocGenerationSliceFlag.
1101
1102func (f *Float64SliceFlag) IsVisible() bool
1103 IsVisible returns true if the flag is not hidden, otherwise false
1104
1105func (f *Float64SliceFlag) Names() []string
1106 Names returns the names of the flag
1107
1108func (f *Float64SliceFlag) RunAction(c *Context) error
1109 RunAction executes flag action if set
1110
1111func (f *Float64SliceFlag) SetDestination(slice []float64)
1112
1113func (f *Float64SliceFlag) SetValue(slice []float64)
1114
1115func (f *Float64SliceFlag) String() string
1116 String returns a readable representation of this value (for usage defaults)
1117
1118func (f *Float64SliceFlag) TakesValue() bool
1119 TakesValue returns true if the flag takes a value, otherwise false
1120
1121func (f *Float64SliceFlag) WithSeparatorSpec(spec separatorSpec)
1122
1123type Generic interface {
1124 Set(value string) error
1125 String() string
1126}
1127 Generic is a generic parseable type identified by a specific flag
1128
1129type GenericFlag struct {
1130 Name string
1131
1132 Category string
1133 DefaultText string
1134 FilePath string
1135 Usage string
1136
1137 Required bool
1138 Hidden bool
1139 HasBeenSet bool
1140
1141 Value Generic
1142 Destination Generic
1143
1144 Aliases []string
1145 EnvVars []string
1146
1147 TakesFile bool
1148
1149 Action func(*Context, interface{}) error
1150 // Has unexported fields.
1151}
1152 GenericFlag is a flag with type Generic
1153
1154func (f *GenericFlag) Apply(set *flag.FlagSet) error
1155 Apply takes the flagset and calls Set on the generic flag with the value
1156 provided by the user for parsing by the flag
1157
1158func (f *GenericFlag) Get(ctx *Context) interface{}
1159 Get returns the flag’s value in the given Context.
1160
1161func (f *GenericFlag) GetCategory() string
1162 GetCategory returns the category for the flag
1163
1164func (f *GenericFlag) GetDefaultText() string
1165 GetDefaultText returns the default text for this flag
1166
1167func (f *GenericFlag) GetEnvVars() []string
1168 GetEnvVars returns the env vars for this flag
1169
1170func (f *GenericFlag) GetUsage() string
1171 GetUsage returns the usage string for the flag
1172
1173func (f *GenericFlag) GetValue() string
1174 GetValue returns the flags value as string representation and an empty
1175 string if the flag takes no value at all.
1176
1177func (f *GenericFlag) IsRequired() bool
1178 IsRequired returns whether or not the flag is required
1179
1180func (f *GenericFlag) IsSet() bool
1181 IsSet returns whether or not the flag has been set through env or file
1182
1183func (f *GenericFlag) IsVisible() bool
1184 IsVisible returns true if the flag is not hidden, otherwise false
1185
1186func (f *GenericFlag) Names() []string
1187 Names returns the names of the flag
1188
1189func (f *GenericFlag) RunAction(c *Context) error
1190 RunAction executes flag action if set
1191
1192func (f *GenericFlag) String() string
1193 String returns a readable representation of this value (for usage defaults)
1194
1195func (f *GenericFlag) TakesValue() bool
1196 TakesValue returns true of the flag takes a value, otherwise false
1197
1198type Int64Flag struct {
1199 Name string
1200
1201 Category string
1202 DefaultText string
1203 FilePath string
1204 Usage string
1205
1206 Required bool
1207 Hidden bool
1208 HasBeenSet bool
1209
1210 Value int64
1211 Destination *int64
1212
1213 Aliases []string
1214 EnvVars []string
1215
1216 Base int
1217
1218 Action func(*Context, int64) error
1219 // Has unexported fields.
1220}
1221 Int64Flag is a flag with type int64
1222
1223func (f *Int64Flag) Apply(set *flag.FlagSet) error
1224 Apply populates the flag given the flag set and environment
1225
1226func (f *Int64Flag) Get(ctx *Context) int64
1227 Get returns the flag’s value in the given Context.
1228
1229func (f *Int64Flag) GetCategory() string
1230 GetCategory returns the category for the flag
1231
1232func (f *Int64Flag) GetDefaultText() string
1233 GetDefaultText returns the default text for this flag
1234
1235func (f *Int64Flag) GetEnvVars() []string
1236 GetEnvVars returns the env vars for this flag
1237
1238func (f *Int64Flag) GetUsage() string
1239 GetUsage returns the usage string for the flag
1240
1241func (f *Int64Flag) GetValue() string
1242 GetValue returns the flags value as string representation and an empty
1243 string if the flag takes no value at all.
1244
1245func (f *Int64Flag) IsRequired() bool
1246 IsRequired returns whether or not the flag is required
1247
1248func (f *Int64Flag) IsSet() bool
1249 IsSet returns whether or not the flag has been set through env or file
1250
1251func (f *Int64Flag) IsVisible() bool
1252 IsVisible returns true if the flag is not hidden, otherwise false
1253
1254func (f *Int64Flag) Names() []string
1255 Names returns the names of the flag
1256
1257func (f *Int64Flag) RunAction(c *Context) error
1258 RunAction executes flag action if set
1259
1260func (f *Int64Flag) String() string
1261 String returns a readable representation of this value (for usage defaults)
1262
1263func (f *Int64Flag) TakesValue() bool
1264 TakesValue returns true of the flag takes a value, otherwise false
1265
1266type Int64Slice struct {
1267 // Has unexported fields.
1268}
1269 Int64Slice wraps []int64 to satisfy flag.Value
1270
1271func NewInt64Slice(defaults ...int64) *Int64Slice
1272 NewInt64Slice makes an *Int64Slice with default values
1273
1274func (i *Int64Slice) Get() interface{}
1275 Get returns the slice of ints set by this flag
1276
1277func (i *Int64Slice) Serialize() string
1278 Serialize allows Int64Slice to fulfill Serializer
1279
1280func (i *Int64Slice) Set(value string) error
1281 Set parses the value into an integer and appends it to the list of values
1282
1283func (i *Int64Slice) String() string
1284 String returns a readable representation of this value (for usage defaults)
1285
1286func (i *Int64Slice) Value() []int64
1287 Value returns the slice of ints set by this flag
1288
1289func (i *Int64Slice) WithSeparatorSpec(spec separatorSpec)
1290
1291type Int64SliceFlag struct {
1292 Name string
1293
1294 Category string
1295 DefaultText string
1296 FilePath string
1297 Usage string
1298
1299 Required bool
1300 Hidden bool
1301 HasBeenSet bool
1302
1303 Value *Int64Slice
1304 Destination *Int64Slice
1305
1306 Aliases []string
1307 EnvVars []string
1308
1309 Action func(*Context, []int64) error
1310 // Has unexported fields.
1311}
1312 Int64SliceFlag is a flag with type *Int64Slice
1313
1314func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error
1315 Apply populates the flag given the flag set and environment
1316
1317func (f *Int64SliceFlag) Get(ctx *Context) []int64
1318 Get returns the flag’s value in the given Context.
1319
1320func (f *Int64SliceFlag) GetCategory() string
1321 GetCategory returns the category for the flag
1322
1323func (f *Int64SliceFlag) GetDefaultText() string
1324 GetDefaultText returns the default text for this flag
1325
1326func (f *Int64SliceFlag) GetDestination() []int64
1327
1328func (f *Int64SliceFlag) GetEnvVars() []string
1329 GetEnvVars returns the env vars for this flag
1330
1331func (f *Int64SliceFlag) GetUsage() string
1332 GetUsage returns the usage string for the flag
1333
1334func (f *Int64SliceFlag) GetValue() string
1335 GetValue returns the flags value as string representation and an empty
1336 string if the flag takes no value at all.
1337
1338func (f *Int64SliceFlag) IsRequired() bool
1339 IsRequired returns whether or not the flag is required
1340
1341func (f *Int64SliceFlag) IsSet() bool
1342 IsSet returns whether or not the flag has been set through env or file
1343
1344func (f *Int64SliceFlag) IsSliceFlag() bool
1345 IsSliceFlag implements DocGenerationSliceFlag.
1346
1347func (f *Int64SliceFlag) IsVisible() bool
1348 IsVisible returns true if the flag is not hidden, otherwise false
1349
1350func (f *Int64SliceFlag) Names() []string
1351 Names returns the names of the flag
1352
1353func (f *Int64SliceFlag) RunAction(c *Context) error
1354 RunAction executes flag action if set
1355
1356func (f *Int64SliceFlag) SetDestination(slice []int64)
1357
1358func (f *Int64SliceFlag) SetValue(slice []int64)
1359
1360func (f *Int64SliceFlag) String() string
1361 String returns a readable representation of this value (for usage defaults)
1362
1363func (f *Int64SliceFlag) TakesValue() bool
1364 TakesValue returns true of the flag takes a value, otherwise false
1365
1366func (f *Int64SliceFlag) WithSeparatorSpec(spec separatorSpec)
1367
1368type IntFlag struct {
1369 Name string
1370
1371 Category string
1372 DefaultText string
1373 FilePath string
1374 Usage string
1375
1376 Required bool
1377 Hidden bool
1378 HasBeenSet bool
1379
1380 Value int
1381 Destination *int
1382
1383 Aliases []string
1384 EnvVars []string
1385
1386 Base int
1387
1388 Action func(*Context, int) error
1389 // Has unexported fields.
1390}
1391 IntFlag is a flag with type int
1392
1393func (f *IntFlag) Apply(set *flag.FlagSet) error
1394 Apply populates the flag given the flag set and environment
1395
1396func (f *IntFlag) Get(ctx *Context) int
1397 Get returns the flag’s value in the given Context.
1398
1399func (f *IntFlag) GetCategory() string
1400 GetCategory returns the category for the flag
1401
1402func (f *IntFlag) GetDefaultText() string
1403 GetDefaultText returns the default text for this flag
1404
1405func (f *IntFlag) GetEnvVars() []string
1406 GetEnvVars returns the env vars for this flag
1407
1408func (f *IntFlag) GetUsage() string
1409 GetUsage returns the usage string for the flag
1410
1411func (f *IntFlag) GetValue() string
1412 GetValue returns the flags value as string representation and an empty
1413 string if the flag takes no value at all.
1414
1415func (f *IntFlag) IsRequired() bool
1416 IsRequired returns whether or not the flag is required
1417
1418func (f *IntFlag) IsSet() bool
1419 IsSet returns whether or not the flag has been set through env or file
1420
1421func (f *IntFlag) IsVisible() bool
1422 IsVisible returns true if the flag is not hidden, otherwise false
1423
1424func (f *IntFlag) Names() []string
1425 Names returns the names of the flag
1426
1427func (f *IntFlag) RunAction(c *Context) error
1428 RunAction executes flag action if set
1429
1430func (f *IntFlag) String() string
1431 String returns a readable representation of this value (for usage defaults)
1432
1433func (f *IntFlag) TakesValue() bool
1434 TakesValue returns true of the flag takes a value, otherwise false
1435
1436type IntSlice struct {
1437 // Has unexported fields.
1438}
1439 IntSlice wraps []int to satisfy flag.Value
1440
1441func NewIntSlice(defaults ...int) *IntSlice
1442 NewIntSlice makes an *IntSlice with default values
1443
1444func (i *IntSlice) Get() interface{}
1445 Get returns the slice of ints set by this flag
1446
1447func (i *IntSlice) Serialize() string
1448 Serialize allows IntSlice to fulfill Serializer
1449
1450func (i *IntSlice) Set(value string) error
1451 Set parses the value into an integer and appends it to the list of values
1452
1453func (i *IntSlice) SetInt(value int)
1454 TODO: Consistently have specific Set function for Int64 and Float64 ? SetInt
1455 directly adds an integer to the list of values
1456
1457func (i *IntSlice) String() string
1458 String returns a readable representation of this value (for usage defaults)
1459
1460func (i *IntSlice) Value() []int
1461 Value returns the slice of ints set by this flag
1462
1463func (i *IntSlice) WithSeparatorSpec(spec separatorSpec)
1464
1465type IntSliceFlag struct {
1466 Name string
1467
1468 Category string
1469 DefaultText string
1470 FilePath string
1471 Usage string
1472
1473 Required bool
1474 Hidden bool
1475 HasBeenSet bool
1476
1477 Value *IntSlice
1478 Destination *IntSlice
1479
1480 Aliases []string
1481 EnvVars []string
1482
1483 Action func(*Context, []int) error
1484 // Has unexported fields.
1485}
1486 IntSliceFlag is a flag with type *IntSlice
1487
1488func (f *IntSliceFlag) Apply(set *flag.FlagSet) error
1489 Apply populates the flag given the flag set and environment
1490
1491func (f *IntSliceFlag) Get(ctx *Context) []int
1492 Get returns the flag’s value in the given Context.
1493
1494func (f *IntSliceFlag) GetCategory() string
1495 GetCategory returns the category for the flag
1496
1497func (f *IntSliceFlag) GetDefaultText() string
1498 GetDefaultText returns the default text for this flag
1499
1500func (f *IntSliceFlag) GetDestination() []int
1501
1502func (f *IntSliceFlag) GetEnvVars() []string
1503 GetEnvVars returns the env vars for this flag
1504
1505func (f *IntSliceFlag) GetUsage() string
1506 GetUsage returns the usage string for the flag
1507
1508func (f *IntSliceFlag) GetValue() string
1509 GetValue returns the flags value as string representation and an empty
1510 string if the flag takes no value at all.
1511
1512func (f *IntSliceFlag) IsRequired() bool
1513 IsRequired returns whether or not the flag is required
1514
1515func (f *IntSliceFlag) IsSet() bool
1516 IsSet returns whether or not the flag has been set through env or file
1517
1518func (f *IntSliceFlag) IsSliceFlag() bool
1519 IsSliceFlag implements DocGenerationSliceFlag.
1520
1521func (f *IntSliceFlag) IsVisible() bool
1522 IsVisible returns true if the flag is not hidden, otherwise false
1523
1524func (f *IntSliceFlag) Names() []string
1525 Names returns the names of the flag
1526
1527func (f *IntSliceFlag) RunAction(c *Context) error
1528 RunAction executes flag action if set
1529
1530func (f *IntSliceFlag) SetDestination(slice []int)
1531
1532func (f *IntSliceFlag) SetValue(slice []int)
1533
1534func (f *IntSliceFlag) String() string
1535 String returns a readable representation of this value (for usage defaults)
1536
1537func (f *IntSliceFlag) TakesValue() bool
1538 TakesValue returns true of the flag takes a value, otherwise false
1539
1540func (f *IntSliceFlag) WithSeparatorSpec(spec separatorSpec)
1541
1542type InvalidFlagAccessFunc func(*Context, string)
1543 InvalidFlagAccessFunc is executed when an invalid flag is accessed from the
1544 context.
1545
1546type MultiError interface {
1547 error
1548 Errors() []error
1549}
1550 MultiError is an error that wraps multiple errors.
1551
1552type MultiFloat64Flag = SliceFlag[*Float64SliceFlag, []float64, float64]
1553 MultiFloat64Flag extends Float64SliceFlag with support for using slices
1554 directly, as Value and/or Destination. See also SliceFlag.
1555
1556type MultiInt64Flag = SliceFlag[*Int64SliceFlag, []int64, int64]
1557 MultiInt64Flag extends Int64SliceFlag with support for using slices
1558 directly, as Value and/or Destination. See also SliceFlag.
1559
1560type MultiIntFlag = SliceFlag[*IntSliceFlag, []int, int]
1561 MultiIntFlag extends IntSliceFlag with support for using slices directly,
1562 as Value and/or Destination. See also SliceFlag.
1563
1564type MultiStringFlag = SliceFlag[*StringSliceFlag, []string, string]
1565 MultiStringFlag extends StringSliceFlag with support for using slices
1566 directly, as Value and/or Destination. See also SliceFlag.
1567
1568type OnUsageErrorFunc func(cCtx *Context, err error, isSubcommand bool) error
1569 OnUsageErrorFunc is executed if a usage error occurs. This is useful for
1570 displaying customized usage error messages. This function is able to replace
1571 the original error messages. If this function is not set, the "Incorrect
1572 usage" is displayed and the execution is interrupted.
1573
1574type Path = string
1575
1576type PathFlag struct {
1577 Name string
1578
1579 Category string
1580 DefaultText string
1581 FilePath string
1582 Usage string
1583
1584 Required bool
1585 Hidden bool
1586 HasBeenSet bool
1587
1588 Value Path
1589 Destination *Path
1590
1591 Aliases []string
1592 EnvVars []string
1593
1594 TakesFile bool
1595
1596 Action func(*Context, Path) error
1597 // Has unexported fields.
1598}
1599 PathFlag is a flag with type Path
1600
1601func (f *PathFlag) Apply(set *flag.FlagSet) error
1602 Apply populates the flag given the flag set and environment
1603
1604func (f *PathFlag) Get(ctx *Context) string
1605 Get returns the flag’s value in the given Context.
1606
1607func (f *PathFlag) GetCategory() string
1608 GetCategory returns the category for the flag
1609
1610func (f *PathFlag) GetDefaultText() string
1611 GetDefaultText returns the default text for this flag
1612
1613func (f *PathFlag) GetEnvVars() []string
1614 GetEnvVars returns the env vars for this flag
1615
1616func (f *PathFlag) GetUsage() string
1617 GetUsage returns the usage string for the flag
1618
1619func (f *PathFlag) GetValue() string
1620 GetValue returns the flags value as string representation and an empty
1621 string if the flag takes no value at all.
1622
1623func (f *PathFlag) IsRequired() bool
1624 IsRequired returns whether or not the flag is required
1625
1626func (f *PathFlag) IsSet() bool
1627 IsSet returns whether or not the flag has been set through env or file
1628
1629func (f *PathFlag) IsVisible() bool
1630 IsVisible returns true if the flag is not hidden, otherwise false
1631
1632func (f *PathFlag) Names() []string
1633 Names returns the names of the flag
1634
1635func (f *PathFlag) RunAction(c *Context) error
1636 RunAction executes flag action if set
1637
1638func (f *PathFlag) String() string
1639 String returns a readable representation of this value (for usage defaults)
1640
1641func (f *PathFlag) TakesValue() bool
1642 TakesValue returns true of the flag takes a value, otherwise false
1643
1644type RequiredFlag interface {
1645 Flag
1646
1647 IsRequired() bool
1648}
1649 RequiredFlag is an interface that allows us to mark flags as required
1650 it allows flags required flags to be backwards compatible with the Flag
1651 interface
1652
1653type Serializer interface {
1654 Serialize() string
1655}
1656 Serializer is used to circumvent the limitations of flag.FlagSet.Set
1657
1658type SliceFlag[T SliceFlagTarget[E], S ~[]E, E any] struct {
1659 Target T
1660 Value S
1661 Destination *S
1662}
1663 SliceFlag extends implementations like StringSliceFlag and IntSliceFlag
1664 with support for using slices directly, as Value and/or Destination.
1665 See also SliceFlagTarget, MultiStringFlag, MultiFloat64Flag, MultiInt64Flag,
1666 MultiIntFlag.
1667
1668func (x *SliceFlag[T, S, E]) Apply(set *flag.FlagSet) error
1669
1670func (x *SliceFlag[T, S, E]) GetCategory() string
1671
1672func (x *SliceFlag[T, S, E]) GetDefaultText() string
1673
1674func (x *SliceFlag[T, S, E]) GetDestination() S
1675
1676func (x *SliceFlag[T, S, E]) GetEnvVars() []string
1677
1678func (x *SliceFlag[T, S, E]) GetUsage() string
1679
1680func (x *SliceFlag[T, S, E]) GetValue() string
1681
1682func (x *SliceFlag[T, S, E]) IsRequired() bool
1683
1684func (x *SliceFlag[T, S, E]) IsSet() bool
1685
1686func (x *SliceFlag[T, S, E]) IsVisible() bool
1687
1688func (x *SliceFlag[T, S, E]) Names() []string
1689
1690func (x *SliceFlag[T, S, E]) SetDestination(slice S)
1691
1692func (x *SliceFlag[T, S, E]) SetValue(slice S)
1693
1694func (x *SliceFlag[T, S, E]) String() string
1695
1696func (x *SliceFlag[T, S, E]) TakesValue() bool
1697
1698type SliceFlagTarget[E any] interface {
1699 Flag
1700 RequiredFlag
1701 DocGenerationFlag
1702 VisibleFlag
1703 CategorizableFlag
1704
1705 // SetValue should propagate the given slice to the target, ideally as a new value.
1706 // Note that a nil slice should nil/clear any existing value (modelled as ~[]E).
1707 SetValue(slice []E)
1708 // SetDestination should propagate the given slice to the target, ideally as a new value.
1709 // Note that a nil slice should nil/clear any existing value (modelled as ~*[]E).
1710 SetDestination(slice []E)
1711 // GetDestination should return the current value referenced by any destination, or nil if nil/unset.
1712 GetDestination() []E
1713}
1714 SliceFlagTarget models a target implementation for use with SliceFlag. The
1715 three methods, SetValue, SetDestination, and GetDestination, are necessary
1716 to propagate Value and Destination, where Value is propagated inwards
1717 (initially), and Destination is propagated outwards (on every update).
1718
1719type StringFlag struct {
1720 Name string
1721
1722 Category string
1723 DefaultText string
1724 FilePath string
1725 Usage string
1726
1727 Required bool
1728 Hidden bool
1729 HasBeenSet bool
1730
1731 Value string
1732 Destination *string
1733
1734 Aliases []string
1735 EnvVars []string
1736
1737 TakesFile bool
1738
1739 Action func(*Context, string) error
1740 // Has unexported fields.
1741}
1742 StringFlag is a flag with type string
1743
1744func (f *StringFlag) Apply(set *flag.FlagSet) error
1745 Apply populates the flag given the flag set and environment
1746
1747func (f *StringFlag) Get(ctx *Context) string
1748 Get returns the flag’s value in the given Context.
1749
1750func (f *StringFlag) GetCategory() string
1751 GetCategory returns the category for the flag
1752
1753func (f *StringFlag) GetDefaultText() string
1754 GetDefaultText returns the default text for this flag
1755
1756func (f *StringFlag) GetEnvVars() []string
1757 GetEnvVars returns the env vars for this flag
1758
1759func (f *StringFlag) GetUsage() string
1760 GetUsage returns the usage string for the flag
1761
1762func (f *StringFlag) GetValue() string
1763 GetValue returns the flags value as string representation and an empty
1764 string if the flag takes no value at all.
1765
1766func (f *StringFlag) IsRequired() bool
1767 IsRequired returns whether or not the flag is required
1768
1769func (f *StringFlag) IsSet() bool
1770 IsSet returns whether or not the flag has been set through env or file
1771
1772func (f *StringFlag) IsVisible() bool
1773 IsVisible returns true if the flag is not hidden, otherwise false
1774
1775func (f *StringFlag) Names() []string
1776 Names returns the names of the flag
1777
1778func (f *StringFlag) RunAction(c *Context) error
1779 RunAction executes flag action if set
1780
1781func (f *StringFlag) String() string
1782 String returns a readable representation of this value (for usage defaults)
1783
1784func (f *StringFlag) TakesValue() bool
1785 TakesValue returns true of the flag takes a value, otherwise false
1786
1787type StringSlice struct {
1788 // Has unexported fields.
1789}
1790 StringSlice wraps a []string to satisfy flag.Value
1791
1792func NewStringSlice(defaults ...string) *StringSlice
1793 NewStringSlice creates a *StringSlice with default values
1794
1795func (s *StringSlice) Get() interface{}
1796 Get returns the slice of strings set by this flag
1797
1798func (s *StringSlice) Serialize() string
1799 Serialize allows StringSlice to fulfill Serializer
1800
1801func (s *StringSlice) Set(value string) error
1802 Set appends the string value to the list of values
1803
1804func (s *StringSlice) String() string
1805 String returns a readable representation of this value (for usage defaults)
1806
1807func (s *StringSlice) Value() []string
1808 Value returns the slice of strings set by this flag
1809
1810func (s *StringSlice) WithSeparatorSpec(spec separatorSpec)
1811
1812type StringSliceFlag struct {
1813 Name string
1814
1815 Category string
1816 DefaultText string
1817 FilePath string
1818 Usage string
1819
1820 Required bool
1821 Hidden bool
1822 HasBeenSet bool
1823
1824 Value *StringSlice
1825 Destination *StringSlice
1826
1827 Aliases []string
1828 EnvVars []string
1829
1830 TakesFile bool
1831
1832 Action func(*Context, []string) error
1833
1834 KeepSpace bool
1835 // Has unexported fields.
1836}
1837 StringSliceFlag is a flag with type *StringSlice
1838
1839func (f *StringSliceFlag) Apply(set *flag.FlagSet) error
1840 Apply populates the flag given the flag set and environment
1841
1842func (f *StringSliceFlag) Get(ctx *Context) []string
1843 Get returns the flag’s value in the given Context.
1844
1845func (f *StringSliceFlag) GetCategory() string
1846 GetCategory returns the category for the flag
1847
1848func (f *StringSliceFlag) GetDefaultText() string
1849 GetDefaultText returns the default text for this flag
1850
1851func (f *StringSliceFlag) GetDestination() []string
1852
1853func (f *StringSliceFlag) GetEnvVars() []string
1854 GetEnvVars returns the env vars for this flag
1855
1856func (f *StringSliceFlag) GetUsage() string
1857 GetUsage returns the usage string for the flag
1858
1859func (f *StringSliceFlag) GetValue() string
1860 GetValue returns the flags value as string representation and an empty
1861 string if the flag takes no value at all.
1862
1863func (f *StringSliceFlag) IsRequired() bool
1864 IsRequired returns whether or not the flag is required
1865
1866func (f *StringSliceFlag) IsSet() bool
1867 IsSet returns whether or not the flag has been set through env or file
1868
1869func (f *StringSliceFlag) IsSliceFlag() bool
1870 IsSliceFlag implements DocGenerationSliceFlag.
1871
1872func (f *StringSliceFlag) IsVisible() bool
1873 IsVisible returns true if the flag is not hidden, otherwise false
1874
1875func (f *StringSliceFlag) Names() []string
1876 Names returns the names of the flag
1877
1878func (f *StringSliceFlag) RunAction(c *Context) error
1879 RunAction executes flag action if set
1880
1881func (f *StringSliceFlag) SetDestination(slice []string)
1882
1883func (f *StringSliceFlag) SetValue(slice []string)
1884
1885func (f *StringSliceFlag) String() string
1886 String returns a readable representation of this value (for usage defaults)
1887
1888func (f *StringSliceFlag) TakesValue() bool
1889 TakesValue returns true of the flag takes a value, otherwise false
1890
1891func (f *StringSliceFlag) WithSeparatorSpec(spec separatorSpec)
1892
1893type SuggestCommandFunc func(commands []*Command, provided string) string
1894
1895type SuggestFlagFunc func(flags []Flag, provided string, hideHelp bool) string
1896
1897type Timestamp struct {
1898 // Has unexported fields.
1899}
1900 Timestamp wrap to satisfy golang's flag interface.
1901
1902func NewTimestamp(timestamp time.Time) *Timestamp
1903 Timestamp constructor
1904
1905func (t *Timestamp) Get() interface{}
1906 Get returns the flag structure
1907
1908func (t *Timestamp) Set(value string) error
1909 Parses the string value to timestamp
1910
1911func (t *Timestamp) SetLayout(layout string)
1912 Set the timestamp string layout for future parsing
1913
1914func (t *Timestamp) SetLocation(loc *time.Location)
1915 Set perceived timezone of the to-be parsed time string
1916
1917func (t *Timestamp) SetTimestamp(value time.Time)
1918 Set the timestamp value directly
1919
1920func (t *Timestamp) String() string
1921 String returns a readable representation of this value (for usage defaults)
1922
1923func (t *Timestamp) Value() *time.Time
1924 Value returns the timestamp value stored in the flag
1925
1926type TimestampFlag struct {
1927 Name string
1928
1929 Category string
1930 DefaultText string
1931 FilePath string
1932 Usage string
1933
1934 Required bool
1935 Hidden bool
1936 HasBeenSet bool
1937
1938 Value *Timestamp
1939 Destination *Timestamp
1940
1941 Aliases []string
1942 EnvVars []string
1943
1944 Layout string
1945
1946 Timezone *time.Location
1947
1948 Action func(*Context, *time.Time) error
1949 // Has unexported fields.
1950}
1951 TimestampFlag is a flag with type *Timestamp
1952
1953func (f *TimestampFlag) Apply(set *flag.FlagSet) error
1954 Apply populates the flag given the flag set and environment
1955
1956func (f *TimestampFlag) Get(ctx *Context) *time.Time
1957 Get returns the flag’s value in the given Context.
1958
1959func (f *TimestampFlag) GetCategory() string
1960 GetCategory returns the category for the flag
1961
1962func (f *TimestampFlag) GetDefaultText() string
1963 GetDefaultText returns the default text for this flag
1964
1965func (f *TimestampFlag) GetEnvVars() []string
1966 GetEnvVars returns the env vars for this flag
1967
1968func (f *TimestampFlag) GetUsage() string
1969 GetUsage returns the usage string for the flag
1970
1971func (f *TimestampFlag) GetValue() string
1972 GetValue returns the flags value as string representation and an empty
1973 string if the flag takes no value at all.
1974
1975func (f *TimestampFlag) IsRequired() bool
1976 IsRequired returns whether or not the flag is required
1977
1978func (f *TimestampFlag) IsSet() bool
1979 IsSet returns whether or not the flag has been set through env or file
1980
1981func (f *TimestampFlag) IsVisible() bool
1982 IsVisible returns true if the flag is not hidden, otherwise false
1983
1984func (f *TimestampFlag) Names() []string
1985 Names returns the names of the flag
1986
1987func (f *TimestampFlag) RunAction(c *Context) error
1988 RunAction executes flag action if set
1989
1990func (f *TimestampFlag) String() string
1991 String returns a readable representation of this value (for usage defaults)
1992
1993func (f *TimestampFlag) TakesValue() bool
1994 TakesValue returns true of the flag takes a value, otherwise false
1995
1996type Uint64Flag struct {
1997 Name string
1998
1999 Category string
2000 DefaultText string
2001 FilePath string
2002 Usage string
2003
2004 Required bool
2005 Hidden bool
2006 HasBeenSet bool
2007
2008 Value uint64
2009 Destination *uint64
2010
2011 Aliases []string
2012 EnvVars []string
2013
2014 Base int
2015
2016 Action func(*Context, uint64) error
2017 // Has unexported fields.
2018}
2019 Uint64Flag is a flag with type uint64
2020
2021func (f *Uint64Flag) Apply(set *flag.FlagSet) error
2022 Apply populates the flag given the flag set and environment
2023
2024func (f *Uint64Flag) Get(ctx *Context) uint64
2025 Get returns the flag’s value in the given Context.
2026
2027func (f *Uint64Flag) GetCategory() string
2028 GetCategory returns the category for the flag
2029
2030func (f *Uint64Flag) GetDefaultText() string
2031 GetDefaultText returns the default text for this flag
2032
2033func (f *Uint64Flag) GetEnvVars() []string
2034 GetEnvVars returns the env vars for this flag
2035
2036func (f *Uint64Flag) GetUsage() string
2037 GetUsage returns the usage string for the flag
2038
2039func (f *Uint64Flag) GetValue() string
2040 GetValue returns the flags value as string representation and an empty
2041 string if the flag takes no value at all.
2042
2043func (f *Uint64Flag) IsRequired() bool
2044 IsRequired returns whether or not the flag is required
2045
2046func (f *Uint64Flag) IsSet() bool
2047 IsSet returns whether or not the flag has been set through env or file
2048
2049func (f *Uint64Flag) IsVisible() bool
2050 IsVisible returns true if the flag is not hidden, otherwise false
2051
2052func (f *Uint64Flag) Names() []string
2053 Names returns the names of the flag
2054
2055func (f *Uint64Flag) RunAction(c *Context) error
2056 RunAction executes flag action if set
2057
2058func (f *Uint64Flag) String() string
2059 String returns a readable representation of this value (for usage defaults)
2060
2061func (f *Uint64Flag) TakesValue() bool
2062 TakesValue returns true of the flag takes a value, otherwise false
2063
2064type Uint64Slice struct {
2065 // Has unexported fields.
2066}
2067 Uint64Slice wraps []int64 to satisfy flag.Value
2068
2069func NewUint64Slice(defaults ...uint64) *Uint64Slice
2070 NewUint64Slice makes an *Uint64Slice with default values
2071
2072func (i *Uint64Slice) Get() interface{}
2073 Get returns the slice of ints set by this flag
2074
2075func (i *Uint64Slice) Serialize() string
2076 Serialize allows Uint64Slice to fulfill Serializer
2077
2078func (i *Uint64Slice) Set(value string) error
2079 Set parses the value into an integer and appends it to the list of values
2080
2081func (i *Uint64Slice) String() string
2082 String returns a readable representation of this value (for usage defaults)
2083
2084func (i *Uint64Slice) Value() []uint64
2085 Value returns the slice of ints set by this flag
2086
2087func (i *Uint64Slice) WithSeparatorSpec(spec separatorSpec)
2088
2089type Uint64SliceFlag struct {
2090 Name string
2091
2092 Category string
2093 DefaultText string
2094 FilePath string
2095 Usage string
2096
2097 Required bool
2098 Hidden bool
2099 HasBeenSet bool
2100
2101 Value *Uint64Slice
2102 Destination *Uint64Slice
2103
2104 Aliases []string
2105 EnvVars []string
2106
2107 Action func(*Context, []uint64) error
2108 // Has unexported fields.
2109}
2110 Uint64SliceFlag is a flag with type *Uint64Slice
2111
2112func (f *Uint64SliceFlag) Apply(set *flag.FlagSet) error
2113 Apply populates the flag given the flag set and environment
2114
2115func (f *Uint64SliceFlag) Get(ctx *Context) []uint64
2116 Get returns the flag’s value in the given Context.
2117
2118func (f *Uint64SliceFlag) GetCategory() string
2119 GetCategory returns the category for the flag
2120
2121func (f *Uint64SliceFlag) GetDefaultText() string
2122 GetDefaultText returns the default text for this flag
2123
2124func (f *Uint64SliceFlag) GetEnvVars() []string
2125 GetEnvVars returns the env vars for this flag
2126
2127func (f *Uint64SliceFlag) GetUsage() string
2128 GetUsage returns the usage string for the flag
2129
2130func (f *Uint64SliceFlag) GetValue() string
2131 GetValue returns the flags value as string representation and an empty
2132 string if the flag takes no value at all.
2133
2134func (f *Uint64SliceFlag) IsRequired() bool
2135 IsRequired returns whether or not the flag is required
2136
2137func (f *Uint64SliceFlag) IsSet() bool
2138 IsSet returns whether or not the flag has been set through env or file
2139
2140func (f *Uint64SliceFlag) IsSliceFlag() bool
2141 IsSliceFlag implements DocGenerationSliceFlag.
2142
2143func (f *Uint64SliceFlag) IsVisible() bool
2144 IsVisible returns true if the flag is not hidden, otherwise false
2145
2146func (f *Uint64SliceFlag) Names() []string
2147 Names returns the names of the flag
2148
2149func (f *Uint64SliceFlag) RunAction(c *Context) error
2150 RunAction executes flag action if set
2151
2152func (f *Uint64SliceFlag) String() string
2153 String returns a readable representation of this value (for usage defaults)
2154
2155func (f *Uint64SliceFlag) TakesValue() bool
2156 TakesValue returns true of the flag takes a value, otherwise false
2157
2158func (f *Uint64SliceFlag) WithSeparatorSpec(spec separatorSpec)
2159
2160type UintFlag struct {
2161 Name string
2162
2163 Category string
2164 DefaultText string
2165 FilePath string
2166 Usage string
2167
2168 Required bool
2169 Hidden bool
2170 HasBeenSet bool
2171
2172 Value uint
2173 Destination *uint
2174
2175 Aliases []string
2176 EnvVars []string
2177
2178 Base int
2179
2180 Action func(*Context, uint) error
2181 // Has unexported fields.
2182}
2183 UintFlag is a flag with type uint
2184
2185func (f *UintFlag) Apply(set *flag.FlagSet) error
2186 Apply populates the flag given the flag set and environment
2187
2188func (f *UintFlag) Get(ctx *Context) uint
2189 Get returns the flag’s value in the given Context.
2190
2191func (f *UintFlag) GetCategory() string
2192 GetCategory returns the category for the flag
2193
2194func (f *UintFlag) GetDefaultText() string
2195 GetDefaultText returns the default text for this flag
2196
2197func (f *UintFlag) GetEnvVars() []string
2198 GetEnvVars returns the env vars for this flag
2199
2200func (f *UintFlag) GetUsage() string
2201 GetUsage returns the usage string for the flag
2202
2203func (f *UintFlag) GetValue() string
2204 GetValue returns the flags value as string representation and an empty
2205 string if the flag takes no value at all.
2206
2207func (f *UintFlag) IsRequired() bool
2208 IsRequired returns whether or not the flag is required
2209
2210func (f *UintFlag) IsSet() bool
2211 IsSet returns whether or not the flag has been set through env or file
2212
2213func (f *UintFlag) IsVisible() bool
2214 IsVisible returns true if the flag is not hidden, otherwise false
2215
2216func (f *UintFlag) Names() []string
2217 Names returns the names of the flag
2218
2219func (f *UintFlag) RunAction(c *Context) error
2220 RunAction executes flag action if set
2221
2222func (f *UintFlag) String() string
2223 String returns a readable representation of this value (for usage defaults)
2224
2225func (f *UintFlag) TakesValue() bool
2226 TakesValue returns true of the flag takes a value, otherwise false
2227
2228type UintSlice struct {
2229 // Has unexported fields.
2230}
2231 UintSlice wraps []int to satisfy flag.Value
2232
2233func NewUintSlice(defaults ...uint) *UintSlice
2234 NewUintSlice makes an *UintSlice with default values
2235
2236func (i *UintSlice) Get() interface{}
2237 Get returns the slice of ints set by this flag
2238
2239func (i *UintSlice) Serialize() string
2240 Serialize allows UintSlice to fulfill Serializer
2241
2242func (i *UintSlice) Set(value string) error
2243 Set parses the value into an integer and appends it to the list of values
2244
2245func (i *UintSlice) SetUint(value uint)
2246 TODO: Consistently have specific Set function for Int64 and Float64 ? SetInt
2247 directly adds an integer to the list of values
2248
2249func (i *UintSlice) String() string
2250 String returns a readable representation of this value (for usage defaults)
2251
2252func (i *UintSlice) Value() []uint
2253 Value returns the slice of ints set by this flag
2254
2255func (i *UintSlice) WithSeparatorSpec(spec separatorSpec)
2256
2257type UintSliceFlag struct {
2258 Name string
2259
2260 Category string
2261 DefaultText string
2262 FilePath string
2263 Usage string
2264
2265 Required bool
2266 Hidden bool
2267 HasBeenSet bool
2268
2269 Value *UintSlice
2270 Destination *UintSlice
2271
2272 Aliases []string
2273 EnvVars []string
2274
2275 Action func(*Context, []uint) error
2276 // Has unexported fields.
2277}
2278 UintSliceFlag is a flag with type *UintSlice
2279
2280func (f *UintSliceFlag) Apply(set *flag.FlagSet) error
2281 Apply populates the flag given the flag set and environment
2282
2283func (f *UintSliceFlag) Get(ctx *Context) []uint
2284 Get returns the flag’s value in the given Context.
2285
2286func (f *UintSliceFlag) GetCategory() string
2287 GetCategory returns the category for the flag
2288
2289func (f *UintSliceFlag) GetDefaultText() string
2290 GetDefaultText returns the default text for this flag
2291
2292func (f *UintSliceFlag) GetEnvVars() []string
2293 GetEnvVars returns the env vars for this flag
2294
2295func (f *UintSliceFlag) GetUsage() string
2296 GetUsage returns the usage string for the flag
2297
2298func (f *UintSliceFlag) GetValue() string
2299 GetValue returns the flags value as string representation and an empty
2300 string if the flag takes no value at all.
2301
2302func (f *UintSliceFlag) IsRequired() bool
2303 IsRequired returns whether or not the flag is required
2304
2305func (f *UintSliceFlag) IsSet() bool
2306 IsSet returns whether or not the flag has been set through env or file
2307
2308func (f *UintSliceFlag) IsSliceFlag() bool
2309 IsSliceFlag implements DocGenerationSliceFlag.
2310
2311func (f *UintSliceFlag) IsVisible() bool
2312 IsVisible returns true if the flag is not hidden, otherwise false
2313
2314func (f *UintSliceFlag) Names() []string
2315 Names returns the names of the flag
2316
2317func (f *UintSliceFlag) RunAction(c *Context) error
2318 RunAction executes flag action if set
2319
2320func (f *UintSliceFlag) String() string
2321 String returns a readable representation of this value (for usage defaults)
2322
2323func (f *UintSliceFlag) TakesValue() bool
2324 TakesValue returns true of the flag takes a value, otherwise false
2325
2326func (f *UintSliceFlag) WithSeparatorSpec(spec separatorSpec)
2327
2328type VisibleFlag interface {
2329 Flag
2330
2331 // IsVisible returns true if the flag is not hidden, otherwise false
2332 IsVisible() bool
2333}
2334 VisibleFlag is an interface that allows to check if a flag is visible
2335
2336type VisibleFlagCategory interface {
2337 // Name returns the category name string
2338 Name() string
2339 // Flags returns a slice of VisibleFlag sorted by name
2340 Flags() []VisibleFlag
2341}
2342 VisibleFlagCategory is a category containing flags.
2343
2344package altsrc // import "github.com/urfave/cli/v2/altsrc"
2345
2346
2347FUNCTIONS
2348
2349func ApplyInputSourceValues(cCtx *cli.Context, inputSourceContext InputSourceContext, flags []cli.Flag) error
2350 ApplyInputSourceValues iterates over all provided flags and executes
2351 ApplyInputSourceValue on flags implementing the FlagInputSourceExtension
2352 interface to initialize these flags to an alternate input source.
2353
2354func InitInputSource(flags []cli.Flag, createInputSource func() (InputSourceContext, error)) cli.BeforeFunc
2355 InitInputSource is used to to setup an InputSourceContext on a cli.Command
2356 Before method. It will create a new input source based on the func provided.
2357 If there is no error it will then apply the new input source to any flags
2358 that are supported by the input source
2359
2360func InitInputSourceWithContext(flags []cli.Flag, createInputSource func(cCtx *cli.Context) (InputSourceContext, error)) cli.BeforeFunc
2361 InitInputSourceWithContext is used to to setup an InputSourceContext on
2362 a cli.Command Before method. It will create a new input source based on
2363 the func provided with potentially using existing cli.Context values to
2364 initialize itself. If there is no error it will then apply the new input
2365 source to any flags that are supported by the input source
2366
2367func NewJSONSourceFromFlagFunc(flag string) func(c *cli.Context) (InputSourceContext, error)
2368 NewJSONSourceFromFlagFunc returns a func that takes a cli.Context and
2369 returns an InputSourceContext suitable for retrieving config variables from
2370 a file containing JSON data with the file name defined by the given flag.
2371
2372func NewTomlSourceFromFlagFunc(flagFileName string) func(cCtx *cli.Context) (InputSourceContext, error)
2373 NewTomlSourceFromFlagFunc creates a new TOML InputSourceContext from a
2374 provided flag name and source context.
2375
2376func NewYamlSourceFromFlagFunc(flagFileName string) func(cCtx *cli.Context) (InputSourceContext, error)
2377 NewYamlSourceFromFlagFunc creates a new Yaml InputSourceContext from a
2378 provided flag name and source context.
2379
2380
2381TYPES
2382
2383type BoolFlag struct {
2384 *cli.BoolFlag
2385 // Has unexported fields.
2386}
2387 BoolFlag is the flag type that wraps cli.BoolFlag to allow for other values
2388 to be specified
2389
2390func NewBoolFlag(fl *cli.BoolFlag) *BoolFlag
2391 NewBoolFlag creates a new BoolFlag
2392
2393func (f *BoolFlag) Apply(set *flag.FlagSet) error
2394 Apply saves the flagSet for later usage calls, then calls the wrapped
2395 BoolFlag.Apply
2396
2397func (f *BoolFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2398 ApplyInputSourceValue applies a Bool value to the flagSet if required
2399
2400type DurationFlag struct {
2401 *cli.DurationFlag
2402 // Has unexported fields.
2403}
2404 DurationFlag is the flag type that wraps cli.DurationFlag to allow for other
2405 values to be specified
2406
2407func NewDurationFlag(fl *cli.DurationFlag) *DurationFlag
2408 NewDurationFlag creates a new DurationFlag
2409
2410func (f *DurationFlag) Apply(set *flag.FlagSet) error
2411 Apply saves the flagSet for later usage calls, then calls the wrapped
2412 DurationFlag.Apply
2413
2414func (f *DurationFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2415 ApplyInputSourceValue applies a Duration value to the flagSet if required
2416
2417type FlagInputSourceExtension interface {
2418 cli.Flag
2419 ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2420}
2421 FlagInputSourceExtension is an extension interface of cli.Flag that allows a
2422 value to be set on the existing parsed flags.
2423
2424type Float64Flag struct {
2425 *cli.Float64Flag
2426 // Has unexported fields.
2427}
2428 Float64Flag is the flag type that wraps cli.Float64Flag to allow for other
2429 values to be specified
2430
2431func NewFloat64Flag(fl *cli.Float64Flag) *Float64Flag
2432 NewFloat64Flag creates a new Float64Flag
2433
2434func (f *Float64Flag) Apply(set *flag.FlagSet) error
2435 Apply saves the flagSet for later usage calls, then calls the wrapped
2436 Float64Flag.Apply
2437
2438func (f *Float64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2439 ApplyInputSourceValue applies a Float64 value to the flagSet if required
2440
2441type Float64SliceFlag struct {
2442 *cli.Float64SliceFlag
2443 // Has unexported fields.
2444}
2445 Float64SliceFlag is the flag type that wraps cli.Float64SliceFlag to allow
2446 for other values to be specified
2447
2448func NewFloat64SliceFlag(fl *cli.Float64SliceFlag) *Float64SliceFlag
2449 NewFloat64SliceFlag creates a new Float64SliceFlag
2450
2451func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error
2452 Apply saves the flagSet for later usage calls, then calls the wrapped
2453 Float64SliceFlag.Apply
2454
2455func (f *Float64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2456 ApplyInputSourceValue applies a Float64Slice value if required
2457
2458type GenericFlag struct {
2459 *cli.GenericFlag
2460 // Has unexported fields.
2461}
2462 GenericFlag is the flag type that wraps cli.GenericFlag to allow for other
2463 values to be specified
2464
2465func NewGenericFlag(fl *cli.GenericFlag) *GenericFlag
2466 NewGenericFlag creates a new GenericFlag
2467
2468func (f *GenericFlag) Apply(set *flag.FlagSet) error
2469 Apply saves the flagSet for later usage calls, then calls the wrapped
2470 GenericFlag.Apply
2471
2472func (f *GenericFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2473 ApplyInputSourceValue applies a generic value to the flagSet if required
2474
2475type InputSourceContext interface {
2476 Source() string
2477
2478 Int(name string) (int, error)
2479 Int64(name string) (int64, error)
2480 Uint(name string) (uint, error)
2481 Uint64(name string) (uint64, error)
2482 Duration(name string) (time.Duration, error)
2483 Float64(name string) (float64, error)
2484 String(name string) (string, error)
2485 StringSlice(name string) ([]string, error)
2486 IntSlice(name string) ([]int, error)
2487 Int64Slice(name string) ([]int64, error)
2488 Float64Slice(name string) ([]float64, error)
2489 Generic(name string) (cli.Generic, error)
2490 Bool(name string) (bool, error)
2491
2492 // Has unexported methods.
2493}
2494 InputSourceContext is an interface used to allow other input sources to be
2495 implemented as needed.
2496
2497 Source returns an identifier for the input source. In case of file source it
2498 should return path to the file.
2499
2500func NewJSONSource(data []byte) (InputSourceContext, error)
2501 NewJSONSource returns an InputSourceContext suitable for retrieving config
2502 variables from raw JSON data.
2503
2504func NewJSONSourceFromFile(f string) (InputSourceContext, error)
2505 NewJSONSourceFromFile returns an InputSourceContext suitable for retrieving
2506 config variables from a file (or url) containing JSON data.
2507
2508func NewJSONSourceFromReader(r io.Reader) (InputSourceContext, error)
2509 NewJSONSourceFromReader returns an InputSourceContext suitable for
2510 retrieving config variables from an io.Reader that returns JSON data.
2511
2512func NewTomlSourceFromFile(file string) (InputSourceContext, error)
2513 NewTomlSourceFromFile creates a new TOML InputSourceContext from a filepath.
2514
2515func NewYamlSourceFromFile(file string) (InputSourceContext, error)
2516 NewYamlSourceFromFile creates a new Yaml InputSourceContext from a filepath.
2517
2518type Int64Flag struct {
2519 *cli.Int64Flag
2520 // Has unexported fields.
2521}
2522 Int64Flag is the flag type that wraps cli.Int64Flag to allow for other
2523 values to be specified
2524
2525func NewInt64Flag(fl *cli.Int64Flag) *Int64Flag
2526 NewInt64Flag creates a new Int64Flag
2527
2528func (f *Int64Flag) Apply(set *flag.FlagSet) error
2529 Apply saves the flagSet for later usage calls, then calls the wrapped
2530 Int64Flag.Apply
2531
2532func (f *Int64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2533
2534type Int64SliceFlag struct {
2535 *cli.Int64SliceFlag
2536 // Has unexported fields.
2537}
2538 Int64SliceFlag is the flag type that wraps cli.Int64SliceFlag to allow for
2539 other values to be specified
2540
2541func NewInt64SliceFlag(fl *cli.Int64SliceFlag) *Int64SliceFlag
2542 NewInt64SliceFlag creates a new Int64SliceFlag
2543
2544func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error
2545 Apply saves the flagSet for later usage calls, then calls the wrapped
2546 Int64SliceFlag.Apply
2547
2548func (f *Int64SliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2549 ApplyInputSourceValue applies a Int64Slice value if required
2550
2551type IntFlag struct {
2552 *cli.IntFlag
2553 // Has unexported fields.
2554}
2555 IntFlag is the flag type that wraps cli.IntFlag to allow for other values to
2556 be specified
2557
2558func NewIntFlag(fl *cli.IntFlag) *IntFlag
2559 NewIntFlag creates a new IntFlag
2560
2561func (f *IntFlag) Apply(set *flag.FlagSet) error
2562 Apply saves the flagSet for later usage calls, then calls the wrapped
2563 IntFlag.Apply
2564
2565func (f *IntFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2566 ApplyInputSourceValue applies a int value to the flagSet if required
2567
2568type IntSliceFlag struct {
2569 *cli.IntSliceFlag
2570 // Has unexported fields.
2571}
2572 IntSliceFlag is the flag type that wraps cli.IntSliceFlag to allow for other
2573 values to be specified
2574
2575func NewIntSliceFlag(fl *cli.IntSliceFlag) *IntSliceFlag
2576 NewIntSliceFlag creates a new IntSliceFlag
2577
2578func (f *IntSliceFlag) Apply(set *flag.FlagSet) error
2579 Apply saves the flagSet for later usage calls, then calls the wrapped
2580 IntSliceFlag.Apply
2581
2582func (f *IntSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2583 ApplyInputSourceValue applies a IntSlice value if required
2584
2585type MapInputSource struct {
2586 // Has unexported fields.
2587}
2588 MapInputSource implements InputSourceContext to return data from the map
2589 that is loaded.
2590
2591func NewMapInputSource(file string, valueMap map[interface{}]interface{}) *MapInputSource
2592 NewMapInputSource creates a new MapInputSource for implementing custom input
2593 sources.
2594
2595func (fsm *MapInputSource) Bool(name string) (bool, error)
2596 Bool returns an bool from the map otherwise returns false
2597
2598func (fsm *MapInputSource) Duration(name string) (time.Duration, error)
2599 Duration returns a duration from the map if it exists otherwise returns 0
2600
2601func (fsm *MapInputSource) Float64(name string) (float64, error)
2602 Float64 returns an float64 from the map if it exists otherwise returns 0
2603
2604func (fsm *MapInputSource) Float64Slice(name string) ([]float64, error)
2605 Float64Slice returns an []float64 from the map if it exists otherwise
2606 returns nil
2607
2608func (fsm *MapInputSource) Generic(name string) (cli.Generic, error)
2609 Generic returns an cli.Generic from the map if it exists otherwise returns
2610 nil
2611
2612func (fsm *MapInputSource) Int(name string) (int, error)
2613 Int returns an int from the map if it exists otherwise returns 0
2614
2615func (fsm *MapInputSource) Int64(name string) (int64, error)
2616 Int64 returns an int64 from the map if it exists otherwise returns 0
2617
2618func (fsm *MapInputSource) Int64Slice(name string) ([]int64, error)
2619 Int64Slice returns an []int64 from the map if it exists otherwise returns
2620 nil
2621
2622func (fsm *MapInputSource) IntSlice(name string) ([]int, error)
2623 IntSlice returns an []int from the map if it exists otherwise returns nil
2624
2625func (fsm *MapInputSource) Source() string
2626 Source returns the path of the source file
2627
2628func (fsm *MapInputSource) String(name string) (string, error)
2629 String returns a string from the map if it exists otherwise returns an empty
2630 string
2631
2632func (fsm *MapInputSource) StringSlice(name string) ([]string, error)
2633 StringSlice returns an []string from the map if it exists otherwise returns
2634 nil
2635
2636func (fsm *MapInputSource) Uint(name string) (uint, error)
2637 Int64 returns an int64 from the map if it exists otherwise returns 0
2638
2639func (fsm *MapInputSource) Uint64(name string) (uint64, error)
2640 UInt64 returns an uint64 from the map if it exists otherwise returns 0
2641
2642type PathFlag struct {
2643 *cli.PathFlag
2644 // Has unexported fields.
2645}
2646 PathFlag is the flag type that wraps cli.PathFlag to allow for other values
2647 to be specified
2648
2649func NewPathFlag(fl *cli.PathFlag) *PathFlag
2650 NewPathFlag creates a new PathFlag
2651
2652func (f *PathFlag) Apply(set *flag.FlagSet) error
2653 Apply saves the flagSet for later usage calls, then calls the wrapped
2654 PathFlag.Apply
2655
2656func (f *PathFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2657 ApplyInputSourceValue applies a Path value to the flagSet if required
2658
2659type StringFlag struct {
2660 *cli.StringFlag
2661 // Has unexported fields.
2662}
2663 StringFlag is the flag type that wraps cli.StringFlag to allow for other
2664 values to be specified
2665
2666func NewStringFlag(fl *cli.StringFlag) *StringFlag
2667 NewStringFlag creates a new StringFlag
2668
2669func (f *StringFlag) Apply(set *flag.FlagSet) error
2670 Apply saves the flagSet for later usage calls, then calls the wrapped
2671 StringFlag.Apply
2672
2673func (f *StringFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2674 ApplyInputSourceValue applies a String value to the flagSet if required
2675
2676type StringSliceFlag struct {
2677 *cli.StringSliceFlag
2678 // Has unexported fields.
2679}
2680 StringSliceFlag is the flag type that wraps cli.StringSliceFlag to allow for
2681 other values to be specified
2682
2683func NewStringSliceFlag(fl *cli.StringSliceFlag) *StringSliceFlag
2684 NewStringSliceFlag creates a new StringSliceFlag
2685
2686func (f *StringSliceFlag) Apply(set *flag.FlagSet) error
2687 Apply saves the flagSet for later usage calls, then calls the wrapped
2688 StringSliceFlag.Apply
2689
2690func (f *StringSliceFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2691 ApplyInputSourceValue applies a StringSlice value to the flagSet if required
2692
2693type Uint64Flag struct {
2694 *cli.Uint64Flag
2695 // Has unexported fields.
2696}
2697 Uint64Flag is the flag type that wraps cli.Uint64Flag to allow for other
2698 values to be specified
2699
2700func NewUint64Flag(fl *cli.Uint64Flag) *Uint64Flag
2701 NewUint64Flag creates a new Uint64Flag
2702
2703func (f *Uint64Flag) Apply(set *flag.FlagSet) error
2704 Apply saves the flagSet for later usage calls, then calls the wrapped
2705 Uint64Flag.Apply
2706
2707func (f *Uint64Flag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2708
2709type UintFlag struct {
2710 *cli.UintFlag
2711 // Has unexported fields.
2712}
2713 UintFlag is the flag type that wraps cli.UintFlag to allow for other values
2714 to be specified
2715
2716func NewUintFlag(fl *cli.UintFlag) *UintFlag
2717 NewUintFlag creates a new UintFlag
2718
2719func (f *UintFlag) Apply(set *flag.FlagSet) error
2720 Apply saves the flagSet for later usage calls, then calls the wrapped
2721 UintFlag.Apply
2722
2723func (f *UintFlag) ApplyInputSourceValue(cCtx *cli.Context, isc InputSourceContext) error
2724
View as plain text