Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Feb 14, 2024
1 parent b71eace commit bfc17c1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion completers/dagger_completer/cmd/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ func init() {
"output": carapace.ActionFiles(),
})

// TODO positional
carapace.Gen(callCmd).PositionalAnyCompletion(
dagger.ActionFunctions(),
)
}
4 changes: 3 additions & 1 deletion completers/dagger_completer/cmd/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ func init() {
"mod": dagger.ActionMods(),
})

// TODO positional
carapace.Gen(functionsCmd).PositionalAnyCompletion(
dagger.ActionFunctions().FilterArgs(),
)
}
2 changes: 1 addition & 1 deletion completers/dagger_completer/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func init() {

carapace.Gen(initCmd).FlagCompletion(carapace.ActionMap{
"license": dagger.ActionLicenses(),
"sdk": dagger.ActionLicenses(),
"sdk": dagger.ActionSdks(),
"source": carapace.ActionDirectories(),
})

Expand Down
23 changes: 23 additions & 0 deletions pkg/actions/tools/dagger/function.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dagger

import (
"regexp"
"strings"

"github.com/rsteube/carapace"
)

func ActionFunctions() carapace.Action {
return carapace.ActionExecCommand("dagger", "functions", "--silent")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
r := regexp.MustCompile(`^(?P<name>[^ ]+) +example usage: "(?P<example>.*)"$`)

vals := make([]string, 0)
for _, line := range lines[1:] {
if matches := r.FindStringSubmatch(line); matches != nil {
vals = append(vals, matches[1], matches[2])
}
}
return carapace.ActionValuesDescribed(vals...)
})
}

0 comments on commit bfc17c1

Please sign in to comment.