-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #848 from rsteube/doc-prerun
doc: PreRun
- Loading branch information
Showing
6 changed files
with
215 additions
and
99 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{"version": 2, "width": 108, "height": 24, "timestamp": 1690471863, "env": {"SHELL": "elvish", "TERM": "tmux-256color"}} | ||
[0.082769, "o", "\u001b[?7h\u001b[7m⏎\u001b[m \r \r\u001b[?7l\u001b[?2004h"] | ||
[0.083393, "o", "\u001b[?25l\r???> ???> \r\u001b[5C\u001b[?25h\u001b[?25l\r\u001b[5C\u001b[K\r\u001b[5C\u001b[?25h"] | ||
[0.09568, "o", "\u001b[?25l\r\r\u001b[5C\u001b[?25h"] | ||
[0.095794, "o", "\u001b[?25l\r\u001b[K\r\n\u001b[0;1;36mcarapace/example\u001b[0;m on \u001b[0;1;35m doc-preinvoke\u001b[0;m \u001b[0;1;31m[$!?]\u001b[0;m via \u001b[0;1;36m🐹 v1.20.6 \r\n\u001b[0;1;37mesh\u001b[0;m \u001b[0;1;32m❯\u001b[0;m \r\u001b[6C\u001b[?25h"] | ||
[0.095847, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"] | ||
[0.412505, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[0;31me\u001b[0;m\r\u001b[7C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"] | ||
[0.413421, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"] | ||
[0.430073, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"] | ||
[0.430152, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"] | ||
[0.604681, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[7C\u001b[0;31mx\u001b[0;m\r\u001b[8C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[8C\u001b[?25h"] | ||
[0.725813, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\u001b[0;32mexa\u001b[0;m\r\u001b[9C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[9C\u001b[?25h"] | ||
[0.836668, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\u001b[0;31mexam\u001b[0;m\r\u001b[10C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[10C\u001b[?25h"] | ||
[0.889595, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[10C\u001b[0;31mp\u001b[0;m\r\u001b[11C\u001b[?25h"] | ||
[0.889894, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[11C\u001b[?25h"] | ||
[0.891132, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[11C\u001b[?25h"] | ||
[0.891192, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[11C\u001b[?25h"] | ||
[1.015919, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[11C\u001b[0;31ml\u001b[0;m\r\u001b[12C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[12C\u001b[?25h"] | ||
[1.06554, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\u001b[0;32mexample\u001b[0;m\r\u001b[13C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[13C\u001b[?25h"] | ||
[1.122077, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[13C \r\u001b[14C\u001b[?25h"] | ||
[1.295771, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[14C\u001b[0;4maction \r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7;34maction\u001b[0;2;7m (action example) \r\n\u001b[0;34malias\u001b[0;2m (action example) \r\n\u001b[0;mchain\u001b[0;2m (shorthand chain) \r\n\u001b[0;mcompletion\u001b[0;2m (Generate the autocompletion script for the specified shell)\r\n\u001b[0;34mflag\u001b[0;2m (flag example) \r\n\u001b[0;mgroup\u001b[0;2m (group example) \r\n\u001b[0;mhelp\u001b[0;2m (Help about any command) \r\n\u001b[0;35minjection\u001b[0;2m (just trying to break things) \r\n\u001b[0;minterspersed\u001b[0;2m (interspersed example) \r\n\u001b[0;33mmodifier\u001b[0;2m (modifier example) \r\n\u001b[0;mmultiparts\u001b[0;2m (multiparts example) \r\n\u001b[0;36mplugin\u001b[0;2m (dynamic plugin command) \r\n\u001b[0;mspecial \u001b[13A\r\u001b[22C\u001b[?25h"] | ||
[1.763322, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\r\n\u001b[22Cp\r\n\r\n\r\n\u001b[1C\u001b[Kompletion\u001b[0;2m (Generate the autocompletion script for the specified shell)\r\n\u001b[0;m\u001b[K\u001b[0;34mflag\u001b[0;2m (flag example) \r\n\u001b[0;m\u001b[Kgroup\u001b[0;2m (group example) \r\n\u001b[0;m\u001b[Khelp\u001b[0;2m (Help about any command) \r\n\u001b[0;m\u001b[Kinterspersed\u001b[0;2m (interspersed example) \r\n\u001b[0;m\u001b[K\u001b[0;33mmodifier\u001b[0;2m (modifier example) \r\n\u001b[0;m\u001b[Kmultiparts\u001b[0;2m (multiparts example) \r\n\u001b[0;m\u001b[K\u001b[0;36mplugin\u001b[0;2m (dynamic plugin command) \r\n\u001b[0;m\u001b[Kspecial \r\n\u001b[J\u001b[A\u001b[11A\r\u001b[23C\u001b[?25h"] | ||
[1.924854, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\r\n\u001b[23Cl\r\n\r\n\r\n\r\n\r\n\r\n\u001b[Kinterspersed\u001b[0;2m (interspersed example) \r\n\u001b[0;m\u001b[K\u001b[0;33mmodifier\u001b[0;2m (modifier example) \r\n\u001b[0;m\u001b[Kmultiparts\u001b[0;2m (multiparts example) \r\n\u001b[0;m\u001b[K\u001b[0;36mplugin\u001b[0;2m (dynamic plugin command) \u001b[0;m\r\n\u001b[J\u001b[A\u001b[9A\r\u001b[24C\u001b[?25h"] | ||
[2.034708, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[14C\u001b[K\u001b[0;4mplugin \r\n\u001b[24C\u001b[0;mu\r\n\u001b[K\u001b[0;7;36mplugin\u001b[0;2;7m (dynamic plugin command)\u001b[0;m\r\n\u001b[J\u001b[A\u001b[1A\r\u001b[25C\u001b[?25h"] | ||
[2.034794, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\r\n\r\n\u001b[1A\r\u001b[25C\u001b[?25h"] | ||
[2.863313, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[14C\u001b[Kplugin \r\n\u001b[J\u001b[A\r\u001b[21C\u001b[?25h"] | ||
[3.296292, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[21Cpl\r\u001b[23C\u001b[?25h"] | ||
[3.778875, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[21C\u001b[K\u001b[0;4mpl1 \r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7mpl1\u001b[0;m pluginArg1\u001b[1A\r\u001b[22C\u001b[?25h"] | ||
[4.517865, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[23C\u001b[K\u001b[0;4muginArg1 \r\n\r\n\u001b[0;m\u001b[Kpl1 \u001b[0;7mpluginArg1\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"] | ||
[5.479275, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[21C\u001b[KpluginArg1 \r\n\u001b[J\u001b[A\r\u001b[32C\u001b[?25h"] | ||
[5.479367, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[32C\u001b[?25h"] | ||
[5.47977, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[32C\u001b[?25h"] | ||
[6.804825, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\r\u001b[6C\u001b[?25h"] | ||
[6.806102, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"] | ||
[6.827759, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"] | ||
[7.105936, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[0;31me\u001b[0;m\r\u001b[7C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"] | ||
[7.289151, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[7C\u001b[0;31mx\u001b[0;m\r\u001b[8C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[8C\u001b[?25h"] | ||
[7.387644, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[8C\u001b[0;31mi\u001b[0;m\r\u001b[9C\u001b[?25h"] | ||
[7.387975, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[9C\u001b[?25h"] | ||
[7.497308, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\u001b[0;32mexit\u001b[0;m\r\u001b[10C\u001b[?25h"] | ||
[7.598899, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\n\r\u001b[?25h\u001b[?7h\u001b[?2004l\r"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
# PreRun | ||
|
||
[`PreRun`] is called before arguments are parsed for the current command and allows modification of its structure. | ||
|
||
```go | ||
carapace.Gen(rootCmd).PreRun(func(cmd *cobra.Command, args []string) { | ||
pluginCmd := &cobra.Command{ | ||
Use: "plugin", | ||
Short: "dynamic plugin command", | ||
GroupID: "plugin", | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
carapace.Gen(pluginCmd).PositionalCompletion( | ||
carapace.ActionValues("pl1", "pluginArg1"), | ||
) | ||
|
||
cmd.AddCommand(pluginCmd) | ||
}) | ||
``` | ||
|
||
![](./preRun.cast) | ||
|
||
[`PreRun`]:https://pkg.go.dev/github.com/rsteube/carapace#Carapace.PreRun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters