Skip to content

Commit

Permalink
cargo: integrate file completion
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 7, 2024
1 parent 5990947 commit 9afb87d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 4 additions & 0 deletions completers/cargo_completer/cmd/action/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ type content struct {

func ActionGithubPackageSearch() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Value) < 4 {
return carapace.ActionMessage("package search needs at least four characters") // TODO limit it for now
}

batch := carapace.Batch()

if len(c.Args) < 1 {
Expand Down
14 changes: 6 additions & 8 deletions completers/cargo_completer/cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/cargo_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/tools/git"
"github.com/rsteube/carapace/pkg/condition"
"github.com/rsteube/carapace/pkg/util"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -67,12 +68,9 @@ func init() {
})

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

return carapace.ActionMultiParts("@", func(c carapace.Context) carapace.Action {
carapace.Batch(
carapace.ActionDirectories(),
carapace.ActionMultiParts("@", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return action.ActionGithubPackageSearch().NoSpace()
Expand All @@ -81,7 +79,7 @@ func init() {
default:
return carapace.ActionValues()
}
})
}),
}).Unless(condition.CompletingPathS),
).ToA(),
)
}

0 comments on commit 9afb87d

Please sign in to comment.