mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
added a Files field to Command for programs that process files provided as arguments after the flags.
This commit is contained in:
parent
f8e1ec56bd
commit
511c187450
1 changed files with 25 additions and 14 deletions
13
command.go
13
command.go
|
@ -42,6 +42,8 @@ type Command struct {
|
||||||
Long string
|
Long string
|
||||||
// Examples of how to use the command
|
// Examples of how to use the command
|
||||||
Example string
|
Example string
|
||||||
|
// Files that are passed to the program after flags
|
||||||
|
Files string
|
||||||
// Full set of flags
|
// Full set of flags
|
||||||
flags *flag.FlagSet
|
flags *flag.FlagSet
|
||||||
// Set of flags childrens of this command will inherit
|
// Set of flags childrens of this command will inherit
|
||||||
|
@ -204,7 +206,7 @@ func (c *Command) UsageTemplate() string {
|
||||||
} else {
|
} else {
|
||||||
return `{{ $cmd := . }}
|
return `{{ $cmd := . }}
|
||||||
Usage: {{if .Runnable}}
|
Usage: {{if .Runnable}}
|
||||||
{{.UseLine}}{{if .HasFlags}} [flags]{{end}}{{end}}{{if .HasSubCommands}}
|
{{.UseLine}}{{if .HasFlags}} [flags]{{end}}{{if .HasFiles}} [files ...]{{end}}{{end}}{{if .HasSubCommands}}
|
||||||
{{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
|
{{ .CommandPath}} [command]{{end}}{{if gt .Aliases 0}}
|
||||||
|
|
||||||
Aliases:
|
Aliases:
|
||||||
|
@ -212,6 +214,10 @@ Aliases:
|
||||||
{{end}}{{if .HasExample}}
|
{{end}}{{if .HasExample}}
|
||||||
Examples:
|
Examples:
|
||||||
{{ .Example }}
|
{{ .Example }}
|
||||||
|
{{end}}
|
||||||
|
{{if .HasFiles}}
|
||||||
|
Files:
|
||||||
|
{{ .Files }}
|
||||||
{{end}}{{ if .HasSubCommands}}
|
{{end}}{{ if .HasSubCommands}}
|
||||||
Available Commands: {{range .Commands}}{{if .Runnable}}
|
Available Commands: {{range .Commands}}{{if .Runnable}}
|
||||||
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
|
||||||
|
@ -708,6 +714,11 @@ func (c *Command) HasParent() bool {
|
||||||
return c.parent != nil
|
return c.parent != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Does the command take file inputs
|
||||||
|
func (c *Command) HasFiles() bool {
|
||||||
|
return c.Files != ""
|
||||||
|
}
|
||||||
|
|
||||||
// Get the complete FlagSet that applies to this command (local and persistent declared here and by all parents)
|
// Get the complete FlagSet that applies to this command (local and persistent declared here and by all parents)
|
||||||
func (c *Command) Flags() *flag.FlagSet {
|
func (c *Command) Flags() *flag.FlagSet {
|
||||||
if c.flags == nil {
|
if c.flags == nil {
|
||||||
|
|
Loading…
Reference in a new issue