-
-
Notifications
You must be signed in to change notification settings - Fork 53
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 #2275 from rsteube/doc-creating-completers
doc: creating completers
- Loading branch information
Showing
11 changed files
with
1,338 additions
and
6 deletions.
There are no files selected for viewing
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
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 @@ | ||
# Best Practices |
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,43 @@ | ||
# Coupled Actions | ||
|
||
Use coupled actions to avoid repetition. | ||
|
||
Sometimes an [Action] depends on the same flag values for multiple subcommands. | ||
Since [ActionCallback] is needed to access these the code can become a bit cumbersome and bloated. | ||
|
||
```go | ||
carapace.Gen(get_allCmd).PositionalCompletion( | ||
carapace.ActionCallback(func(c carapace.Context) carapace.Action { | ||
return helm.ActionReleases(helm.ReleasesOpts{ | ||
Namespace: rootCmd.Flag("namespace").Value.String(), | ||
KubeContext: rootCmd.Flag("kube-context").Value.String(), | ||
}) | ||
}), | ||
) | ||
``` | ||
|
||
An alternative to this is creating a local [Action] that is coupled to the command. | ||
Meaning, passing it the command and expecting specific flags to be present. | ||
|
||
```go | ||
// completers/helm_completer/cmd/action/release.go | ||
func ActionReleases(cmd *cobra.Command) carapace.Action { | ||
return carapace.ActionCallback(func(c carapace.Context) carapace.Action { | ||
return helm.ActionReleases(helm.ReleasesOpts{ | ||
Namespace: cmd.Root().Flag("namespace").Value.String(), | ||
KubeContext: cmd.Root().Flag("kube-context").Value.String(), | ||
}) | ||
}) | ||
} | ||
``` | ||
|
||
Thus the call becomes quite compact. | ||
|
||
```go | ||
carapace.Gen(get_allCmd).PositionalCompletion( | ||
action.ActionReleases(get_allCmd), | ||
) | ||
``` | ||
|
||
[Action]:https://rsteube.github.io/carapace/carapace/action.html | ||
[ActionCallback]:https://rsteube.github.io/carapace/carapace/defaultActions/actionCallback.html |
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
1,248 changes: 1,248 additions & 0 deletions
1,248
docs/src/development/creatingCompleters/manually.cast
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Manually | ||
|
||
- Copy a basic completer for simplicity. | ||
|
||
```sh | ||
cp -r completers/ln_completer completers/manually_completer | ||
``` | ||
|
||
- Update the package name in `main.go`. | ||
|
||
```diff | ||
-import "github.com/rsteube/carapace-bin/completers/ln_completer/cmd" | ||
+import "github.com/rsteube/carapace-bin/completers/manually_completer/cmd" | ||
``` | ||
|
||
- Create the root command. | ||
|
||
```sh | ||
echo | carapace-parse -n manually > root.go | ||
``` | ||
|
||
- Add subcommands. | ||
|
||
```sh | ||
echo | carapace-parse -n subcommand -p root > subcommand.go | ||
``` | ||
|
||
- Define flags and completions. | ||
|
||
- [Build and install](../build.md#development). | ||
|
||
![](./manually.cast) |
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 @@ | ||
# Parsing |
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 @@ | ||
# Scraping |
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 @@ | ||
# Updating Completers |