Skip to content

Commit

Permalink
Merge pull request #1871 from rsteube/doc-conditions
Browse files Browse the repository at this point in the history
doc: added conditions
  • Loading branch information
rsteube authored Sep 25, 2023
2 parents 582b72a + 11c552e commit 6e0d2db
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
sed -i 's/\[output.linkcheck\]/#[output.linkcheck]/' docs/book.toml
sh .github/completers.sh > docs/src/completers.md
sh .github/macros.sh > docs/src/spec/macros.md
cmd/carapace/carapace --conditions=markdown > docs/src/variable/conditions.md
mdbook build docs
sh .github/badge.sh > docs/book/badge.svg
sh .github/macros-badge.sh > docs/book/macros-badge.svg
Expand Down
24 changes: 19 additions & 5 deletions cmd/carapace/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ var rootCmd = &cobra.Command{
ValidArgs: completers.Names(),
Run: func(cmd *cobra.Command, args []string) {
// since flag parsing is disabled do this manually
// TODO switch to cobra flag parsing with interspersed=false (redirect completion from completers/carapace_completer to here)
switch args[0] {
case "--conditions":
if len(args) > 1 {
//printCondition(args[1]) // TODO
} else {
printConditions() // TODO
fmt.Fprintln(cmd.OutOrStdout(), printConditions("yaml-short")) // TODO
}
case "--conditions=markdown":
fmt.Fprintln(cmd.OutOrStdout(), printConditions("markdown")) // TODO
case "--macros":
if len(args) > 1 {
printMacro(args[1])
Expand Down Expand Up @@ -309,11 +312,22 @@ func printCompletersJson() {
}
}

func printConditions() {
// TODO marshal ordered using yaml
for name, macro := range conditions.MacroMap {
fmt.Printf("%v: %#v\n", name, macro.Description)
func printConditions(format string) string {
s := make([]string, 0)
switch format {
case "yaml-short":
// TODO marshal ordered using yaml
for name, macro := range conditions.MacroMap {
s = append(s, fmt.Sprintf("%v: %#v", name, macro.Description))
}

case "markdown":
s = append(s, "# Conditions", "")
for name, macro := range conditions.MacroMap {
s = append(s, fmt.Sprintf("- [%v](https://pkg.go.dev/github.com/rsteube/carapace-bin/pkg/conditions#Condition%v) %v", name, name, macro.Description))
}
}
return strings.Join(s, "\n")
}

func printMacros() {
Expand Down
3 changes: 2 additions & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
- [Examples](./spec/examples.md)
- [Macros](./spec/macros.md)
- [Overlay](./overlay.md)
- [Environment](./environment.md)
- [Variable](./variable.md)
- [Conditions](./variable/conditions.md)
- [Development](./development.md)
- [Build](./development/build.md)
- [docker-compose](./development/docker-compose.md)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 4 additions & 6 deletions docs/src/environment.md → docs/src/variable.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Environment
# Variable

> feature in development
Expand All @@ -9,7 +9,7 @@ For other shells custom functions are added.

> Setting `CARAPACE_ENV=0` before sourcing `carapace _carapace` disables this behaviour.
![](./environment.cast)
![](./variable.cast)

## Custom variables

Expand All @@ -27,7 +27,7 @@ completion:
HTTPS_PROXY: ["https://localhost:8443\tdevelopment", "https://proxy.company:443\tproduction"]
```
![](./environment-custom.cast)
![](./variable-custom.cast)
It is also possible to define conditions.
Expand All @@ -40,6 +40,4 @@ completion:
CUSTOM_CONDITION: ["within", "git", "repo"]
```
![](./environment-condition.cast)
> TODO document conditions
![](./variable-condition.cast)
3 changes: 3 additions & 0 deletions docs/src/variable/conditions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Conditions

_filled automatically_

0 comments on commit 6e0d2db

Please sign in to comment.