Skip to content

Commit

Permalink
updated carapace
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Apr 11, 2023
1 parent 0d3f425 commit 942ba45
Show file tree
Hide file tree
Showing 119 changed files with 227 additions and 228 deletions.
2 changes: 1 addition & 1 deletion cmd/carapace/cmd/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func addAliasCompletion(cmd *cobra.Command, specCommand spec.Command) {
execArgs := []string{mArgs[0], "export", mArgs[0]}
execArgs = append(execArgs, mArgs[1:]...)
execArgs = append(execArgs, c.Args...)
execArgs = append(execArgs, c.CallbackValue)
execArgs = append(execArgs, c.Value)
return carapace.ActionExecCommand("carapace", execArgs...)(func(output []byte) carapace.Action {
return carapace.ActionImport(output)
})
Expand Down
4 changes: 2 additions & 2 deletions completers/aws_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func init() {

carapace.Gen(rootCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
current := c.CallbackValue
if c.CallbackValue == "-" {
current := c.Value
if c.Value == "-" {
return carapace.ActionValues("--").NoSpace() // no shorthand flags so expand to longhand first (which is needed for the completer)
}

Expand Down
4 changes: 2 additions & 2 deletions completers/brew_completer/cmd/action/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (

func ActionSearch(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.CallbackValue) < 2 {
if len(c.Value) < 2 {
return carapace.ActionMessage("search needs at least 2 characters")
}

args := append([]string{"search"}, defaultArgs(cmd)...)
args = append(args, fmt.Sprintf("/^%v/", c.CallbackValue))
args = append(args, fmt.Sprintf("/^%v/", c.Value))
return carapace.ActionExecCommand("brew", args...)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")

Expand Down
2 changes: 1 addition & 1 deletion completers/carapace_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func posCmd() *cobra.Command {
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
args := []string{c.Args[0], "export", c.Args[0]}
args = append(args, c.Args[3:]...)
args = append(args, c.CallbackValue)
args = append(args, c.Value)
return carapace.ActionExecCommand("carapace", args...)(func(output []byte) carapace.Action {
if string(output) == "" {
return carapace.ActionValues()
Expand Down
12 changes: 6 additions & 6 deletions completers/cargo-watch_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ func init() {
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"exec": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
// very simple support for exec completion (breaks easy
c.CallbackValue = c.CallbackValue + "FAKE_SUFFIX"
fields := strings.Fields(c.CallbackValue) // TODO dumb split on space
c.Value = c.Value + "FAKE_SUFFIX"
fields := strings.Fields(c.Value) // TODO dumb split on space

fields[len(fields)-1] = strings.TrimSuffix(fields[len(fields)-1], "FAKE_SUFFIX")

c.CallbackValue = fields[len(fields)-1]
c.Value = fields[len(fields)-1]
c.Args = make([]string, 0)
if len(fields) > 1 {
c.Args = fields[:len(fields)-1]
Expand All @@ -71,12 +71,12 @@ func init() {
"features": carapace.ActionValues(), // TODO cargo feature completion
"shell": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
// very simple support for exec completion (breaks easy
c.CallbackValue = c.CallbackValue + "FAKE_SUFFIX"
fields := strings.Fields(c.CallbackValue) // TODO dumb split on space
c.Value = c.Value + "FAKE_SUFFIX"
fields := strings.Fields(c.Value) // TODO dumb split on space

fields[len(fields)-1] = strings.TrimSuffix(fields[len(fields)-1], "FAKE_SUFFIX")

c.CallbackValue = fields[len(fields)-1]
c.Value = fields[len(fields)-1]
c.Args = make([]string, 0)
if len(fields) > 1 {
c.Args = fields[:len(fields)-1]
Expand Down
10 changes: 5 additions & 5 deletions completers/cargo_completer/cmd/action/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func ActionPackageSearch() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
// TODO crates.io has no prefix search so the results aren't very helpful at the moment
return carapace.ActionExecCommand("cargo", "search", "--limit", "100", c.CallbackValue)(func(output []byte) carapace.Action {
return carapace.ActionExecCommand("cargo", "search", "--limit", "100", c.Value)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
r := regexp.MustCompile(`^(?P<name>[^ ]+) = "(?P<version>[^"]+)" +#( (?P<description>.*))?$`)

Expand Down Expand Up @@ -57,11 +57,11 @@ func ActionGithubPackageSearch() carapace.Action {
batch = append(batch, actionGithubPackageIndex("3"))
}

if len(c.CallbackValue) > 3 {
batch = append(batch, actionGithubPackageIndex(fmt.Sprintf("%v/%v", c.CallbackValue[0:2], c.CallbackValue[2:4])))
} else if len(c.CallbackValue) > 1 {
if len(c.Value) > 3 {
batch = append(batch, actionGithubPackageIndex(fmt.Sprintf("%v/%v", c.Value[0:2], c.Value[2:4])))
} else if len(c.Value) > 1 {
batch = append(batch, carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return actionGithubPackageIndex(c.CallbackValue[0:2]).Invoke(c).Prefix(c.CallbackValue[0:2]).ToA()
return actionGithubPackageIndex(c.Value[0:2]).Invoke(c).Prefix(c.Value[0:2]).ToA()
}))
}

Expand Down
2 changes: 1 addition & 1 deletion completers/cargo_completer/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func init() {

carapace.Gen(addCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if util.HasPathPrefix(c.CallbackValue) {
if util.HasPathPrefix(c.Value) {
return carapace.ActionDirectories()
}

Expand Down
2 changes: 1 addition & 1 deletion completers/clamdtop_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func init() {

carapace.Gen(rootCmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if util.HasPathPrefix(c.CallbackValue) {
if util.HasPathPrefix(c.Value) {
return carapace.ActionFiles()
}
return carapace.ActionMultiParts(":", func(c carapace.Context) carapace.Action {
Expand Down
8 changes: 4 additions & 4 deletions completers/code_completer/cmd/action/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ type searchResult struct {

func ActionExtensionSearch(category string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.CallbackValue) < 2 {
if len(c.Value) < 2 {
// skip search when less than two characters
return ActionMicrosoftExtensions(category)
}

term := ""
if splitted := strings.SplitN(c.CallbackValue, ".", 2); len(splitted) > 1 && len(splitted[1]) > 0 {
if splitted := strings.SplitN(c.Value, ".", 2); len(splitted) > 1 && len(splitted[1]) > 0 {
term = fmt.Sprintf("publisher:%v +%v", splitted[0], splitted[1])
} else {
term = "publisher:" + splitted[0]
Expand Down Expand Up @@ -71,7 +71,7 @@ func ActionExtensionSearch(category string) carapace.Action {
}
}

if c.CallbackValue != "Microsoft" {
if c.Value != "Microsoft" {
return carapace.Batch(
carapace.ActionValuesDescribed(vals...),
ActionMicrosoftExtensions(category), // always add microsoft extensions since searching for the aliased publisher is not working
Expand All @@ -86,6 +86,6 @@ func ActionExtensionSearch(category string) carapace.Action {
func ActionMicrosoftExtensions(category string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
// Microsoft extensions are aliased and only found by the 'Microsoft' publisher (though the actual name differs)
return ActionExtensionSearch(category).Invoke(carapace.Context{CallbackValue: "Microsoft"}).ToA()
return ActionExtensionSearch(category).Invoke(carapace.Context{Value: "Microsoft"}).ToA()
}).Cache(24*time.Hour, cache.String(category))
}
2 changes: 1 addition & 1 deletion completers/code_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func init() {
}
}),
"install-extension": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if util.HasPathPrefix(c.CallbackValue) {
if util.HasPathPrefix(c.Value) {
return carapace.ActionFiles(".vsix")
}
return action.ActionExtensionSearch(rootCmd.Flag("category").Value.String())
Expand Down
2 changes: 1 addition & 1 deletion completers/consul_completer/cmd/action/keyValue.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func ActionKeys() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionExecCommand("consul", "kv", "get", "--keys", c.CallbackValue)(func(output []byte) carapace.Action {
return carapace.ActionExecCommand("consul", "kv", "get", "--keys", c.Value)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
return carapace.ActionValues(lines[:len(lines)-1]...)
})
Expand Down
2 changes: 1 addition & 1 deletion completers/docker-compose_completer/cmd/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {

carapace.Gen(cpCmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if util.HasPathPrefix(c.CallbackValue) {
if util.HasPathPrefix(c.Value) {
return carapace.ActionFiles()
}
return carapace.ActionMultiParts(":", func(c carapace.Context) carapace.Action {
Expand Down
2 changes: 1 addition & 1 deletion completers/docker_completer/cmd/container_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func init() {
rootAlias(container_cpCmd, func(cmd *cobra.Command, isAlias bool) {
carapace.Gen(cmd).PositionalCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if util.HasPathPrefix(c.CallbackValue) {
if util.HasPathPrefix(c.Value) {
return carapace.ActionFiles()
}
return docker.ActionContainerPath()
Expand Down
4 changes: 2 additions & 2 deletions completers/ebook-convert_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {
carapace.Batch(
carapace.ActionFiles(),
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if index := strings.LastIndex(c.CallbackValue, "."); index != -1 {
if index := strings.LastIndex(c.Value, "."); index != -1 {
return carapace.ActionValuesDescribed(
"mobi", "Mobipocket",
"epub", "Electronic Publication",
Expand All @@ -49,7 +49,7 @@ func init() {
"txt", "Plain Text File",
"txtz", "Zipped Plain Text File",
"zip", "Zipped File",
).Invoke(c).Prefix(c.CallbackValue[:index+1]).ToA().StyleF(style.ForPathExt)
).Invoke(c).Prefix(c.Value[:index+1]).ToA().StyleF(style.ForPathExt)
}
return carapace.ActionValues()
}),
Expand Down
2 changes: 1 addition & 1 deletion completers/gcloud_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
// TODO patch user@instance and --flag=optarg as in gcloud completion script

if c.CallbackValue == "-" {
if c.Value == "-" {
return carapace.ActionValues("--").NoSpace() // seems shorthand flags aren't completed anyway so expand to longhand first
}
c.Setenv("CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK", "1")
Expand Down
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/action/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func ActionApiV3Paths(cmd *cobra.Command) carapace.Action {
fakeRepoFlag(cmd, matchedData["{owner}"], matchedData["{repo}"])
return ActionIssues(cmd, IssueOpts{Open: true, Closed: true})
case "{owner}":
if strings.HasPrefix(c.CallbackValue, ":") {
if strings.HasPrefix(c.Value, ":") {
return carapace.ActionValues(":owner")
} else {
return gh.ActionOwners(gh.HostOpts{}) // TODO host
Expand All @@ -88,7 +88,7 @@ func ActionApiV3Paths(cmd *cobra.Command) carapace.Action {
fakeRepoFlag(cmd, matchedData["{owner}"], matchedData["{repo}"])
return ActionPullRequests(cmd, PullRequestOpts{Open: true, Closed: true, Merged: true})
case "{repo}":
if strings.HasPrefix(c.CallbackValue, ":") {
if strings.HasPrefix(c.Value, ":") {
return carapace.ActionValues(":repo")
} else {
return gh.ActionRepositories(gh.OwnerOpts{Owner: matchedData["{owner}"]})
Expand Down
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/action/codespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func ActionCodespaces() carapace.Action {

func ActionCodespacePath(codespace string, expand bool) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
path := filepath.Dir(c.CallbackValue)
path := filepath.Dir(c.Value)

if !expand {
// scp treats each filename argument as a shell expression,
Expand All @@ -47,7 +47,7 @@ func ActionCodespacePath(codespace string, expand bool) carapace.Action {
}

args := []string{"codespace", "ssh", "--codespace", codespace, "--", "ls", "-1", "-p", path}
if splitted := strings.Split(c.CallbackValue, "/"); strings.HasPrefix(splitted[len(splitted)-1], ".") {
if splitted := strings.Split(c.Value, "/"); strings.HasPrefix(splitted[len(splitted)-1], ".") {
args = append(args, "-a") // show hidden
}
return carapace.ActionMultiParts("/", func(c carapace.Context) carapace.Action {
Expand Down
6 changes: 3 additions & 3 deletions completers/gh_completer/cmd/action/gist.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type gistQuery struct {
func ActionGistUrls(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
prefix := "https://gist."
if !strings.HasPrefix(c.CallbackValue, prefix) {
if !strings.HasPrefix(c.Value, prefix) {
// ActionMultiParts to force nospace (should maybe added as function to InvokedAction to prevent space suffix)
return carapace.ActionMultiParts(".", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
Expand All @@ -44,7 +44,7 @@ func ActionGistUrls(cmd *cobra.Command) carapace.Action {
}
})
} else {
c.CallbackValue = strings.TrimPrefix(c.CallbackValue, prefix)
c.Value = strings.TrimPrefix(c.Value, prefix)
return carapace.ActionMultiParts("/", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
Expand Down Expand Up @@ -89,7 +89,7 @@ func ActionGistIds(cmd *cobra.Command) carapace.Action {

func ActionGists(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if strings.HasPrefix(c.CallbackValue, "h") {
if strings.HasPrefix(c.Value, "h") {
return ActionGistUrls(cmd)
} else {
return ActionGistIds(cmd)
Expand Down
8 changes: 4 additions & 4 deletions completers/gh_completer/cmd/action/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
func ActionBody(cmd *cobra.Command) carapace.Action {
return carapace.ActionMultiParts(" ", func(c carapace.Context) carapace.Action {
switch {
case strings.HasPrefix(c.CallbackValue, ":"):
case strings.HasPrefix(c.Value, ":"):
return gh.ActionEmojis()

case strings.HasPrefix(c.CallbackValue, "@"):
c.CallbackValue = strings.TrimPrefix(c.CallbackValue, "@")
case strings.HasPrefix(c.Value, "@"):
c.Value = strings.TrimPrefix(c.Value, "@")
return ActionMentionableUsers(cmd).Invoke(c).Prefix("@").ToA()

default:
Expand All @@ -43,7 +43,7 @@ func ActionKeywordLinks(cmd *cobra.Command) carapace.Action {
return carapace.ActionMultiParts("#", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
if strings.Contains(c.CallbackValue, "/") {
if strings.Contains(c.Value, "/") {
return ActionOwnerRepositories(cmd).Invoke(c).Suffix("#").ToA()
}
return ActionOwnerRepositories(cmd)
Expand Down
2 changes: 1 addition & 1 deletion completers/gh_completer/cmd/action/repo_override.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func ActionRepoOverride(cmd *cobra.Command) carapace.Action {
if _, err := util.FindReverse(c.Dir, ".git"); err == nil {
actions = append(actions, actionRemoteRepositories())
}
if c.CallbackValue != "" || len(actions) == 0 {
if c.Value != "" || len(actions) == 0 {
actions = append(actions, ActionOwnerRepositories(cmd))
}
return carapace.Batch(actions...).Invoke(c).Merge().ToA()
Expand Down
10 changes: 5 additions & 5 deletions completers/gh_completer/cmd/action/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ func ActionSearchRepositoryFields() carapace.Action {
func ActionSearchRange(a carapace.Action) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
prefix := ""
if strings.HasPrefix(c.CallbackValue, "<=") || strings.HasPrefix(c.CallbackValue, ">=") {
prefix = c.CallbackValue[:2]
} else if strings.HasPrefix(c.CallbackValue, "<") || strings.HasPrefix(c.CallbackValue, ">") {
prefix = c.CallbackValue[:1]
if strings.HasPrefix(c.Value, "<=") || strings.HasPrefix(c.Value, ">=") {
prefix = c.Value[:2]
} else if strings.HasPrefix(c.Value, "<") || strings.HasPrefix(c.Value, ">") {
prefix = c.Value[:1]
}

return carapace.Batch(
Expand All @@ -108,7 +108,7 @@ func ActionSearchRange(a carapace.Action) carapace.Action {
),
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if prefix != "" {
c.CallbackValue = strings.TrimPrefix(c.CallbackValue, prefix)
c.Value = strings.TrimPrefix(c.Value, prefix)
return a.Invoke(c).Prefix(prefix).ToA()

}
Expand Down
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/action/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type topicQuery struct {

func ActionTopicSearch(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.CallbackValue) < 2 {
if len(c.Value) < 2 {
return carapace.ActionMessage("topic search needs at least two characters")
}

var queryResult topicQuery
return ApiV3Action(cmd, fmt.Sprintf(`search/topics?per_page=100&q=%v`, url.QueryEscape(c.CallbackValue)), &queryResult, func() carapace.Action {
return ApiV3Action(cmd, fmt.Sprintf(`search/topics?per_page=100&q=%v`, url.QueryEscape(c.Value)), &queryResult, func() carapace.Action {
vals := make([]string, 0, len(queryResult.Items)*2)
for _, topic := range queryResult.Items {
vals = append(vals, topic.Name, topic.ShortDescription)
Expand Down
4 changes: 2 additions & 2 deletions completers/gh_completer/cmd/action/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type mentionableUsersQuery struct {
func ActionMentionableUsers(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
var queryResult mentionableUsersQuery
return GraphQlAction(cmd, fmt.Sprintf(`repository(owner: $owner, name: $repo){ mentionableUsers(first: 100, query: "%v") { nodes { login, name } } }`, c.CallbackValue), &queryResult, func() carapace.Action {
return GraphQlAction(cmd, fmt.Sprintf(`repository(owner: $owner, name: $repo){ mentionableUsers(first: 100, query: "%v") { nodes { login, name } } }`, c.Value), &queryResult, func() carapace.Action {
users := queryResult.Data.Repository.MentionableUsers.Nodes
vals := make([]string, len(users)*2)
for index, user := range users {
Expand Down Expand Up @@ -50,7 +50,7 @@ type assignableUserQuery struct {
func ActionAssignableUsers(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
var queryResult assignableUserQuery
return GraphQlAction(cmd, fmt.Sprintf(`repository(owner: $owner, name: $repo){ assignableUsers(first: 100, query: "%v") { nodes { login, name } } }`, c.CallbackValue), &queryResult, func() carapace.Action {
return GraphQlAction(cmd, fmt.Sprintf(`repository(owner: $owner, name: $repo){ assignableUsers(first: 100, query: "%v") { nodes { login, name } } }`, c.Value), &queryResult, func() carapace.Action {
users := queryResult.Data.Repository.AssignableUsers.Nodes
vals := make([]string, len(users)*2)
for index, user := range users {
Expand Down
6 changes: 3 additions & 3 deletions completers/gh_completer/cmd/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func init() {
}
}

path := filepath.Dir(c.CallbackValue)
path := filepath.Dir(c.Value)
path = strings.TrimPrefix(path, "/")
if !strings.HasPrefix(c.CallbackValue, "/") {
if !strings.HasPrefix(c.Value, "/") {
root, err := util.FindReverse(c.Dir, ".git")
if err != nil {
return carapace.ActionMessage(err.Error())
Expand All @@ -76,7 +76,7 @@ func init() {
if err != nil {
return carapace.ActionMessage(err.Error())
}
abs := fmt.Sprintf("%v/%v", rel, c.CallbackValue)
abs := fmt.Sprintf("%v/%v", rel, c.Value)
r := regexp.MustCompile(`[^\/]+\/\.\.\/`)
for {
if match := r.FindString(abs); match != "" {
Expand Down
Loading

0 comments on commit 942ba45

Please sign in to comment.