mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
Add documentation for PostTerminatorArgs
This commit is contained in:
parent
94b8e4d5df
commit
db7f74ab37
1 changed files with 23 additions and 1 deletions
|
@ -410,7 +410,7 @@ var cmd = &cobra.Command{
|
|||
}
|
||||
```
|
||||
|
||||
## Example
|
||||
### Example
|
||||
|
||||
In the example below, we have defined three commands. Two are at the top level
|
||||
and one (cmdTimes) is a child of one of the top commands. In this case the root
|
||||
|
@ -480,6 +480,28 @@ a count and a string.`,
|
|||
|
||||
For a more complete example of a larger application, please checkout [Hugo](https://gohugo.io/).
|
||||
|
||||
### post arg terminator "--" args
|
||||
|
||||
By default args passed to the Run method will include arguments passed after
|
||||
the arg terminator "--". You can change this behavior by setting the field
|
||||
IgnorePostTerminatorArgs to true. You can retrieve these arguments easily by
|
||||
calling the PostTerminatorArgs() method of the command. This can be useful when
|
||||
calling child command from your program.
|
||||
|
||||
```go
|
||||
var cmd = &cobra.Command{
|
||||
Use: "exec",
|
||||
IgnorePostTerminatorArgs: true,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
bin := args[0]
|
||||
//...pass all args after -- to the underlying command
|
||||
cmd := exec.Command(bin, cmd.PostTerminatorArgs())
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Help Command
|
||||
|
||||
Cobra automatically adds a help command to your application when you have subcommands.
|
||||
|
|
Loading…
Reference in a new issue