Skip to content

Commit

Permalink
carapace: support sandbox tests in carapace-bin
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Dec 22, 2023
1 parent fdb4093 commit b2fb14a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/actions/bridge/carapace.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package bridge

import (
"os"
"path/filepath"
"strings"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -29,11 +33,16 @@ func ActionCarapace(command ...string) carapace.Action {
func ActionCarapaceBin(command ...string) carapace.Action {
return actionCommand(command...)(func(command ...string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
cmd := "carapace"
if executable, err := os.Executable(); err == nil && strings.HasPrefix(executable, os.TempDir()) && filepath.Base(executable) == "carapace" {
cmd = executable // workaround for sandbox tests: directly call executable which was built with "go run"
}

args := []string{command[0], "export", ""}
args = append(args, command[1:]...)
args = append(args, c.Args...)
args = append(args, c.Value)
return carapace.ActionExecCommand("carapace", args...)(func(output []byte) carapace.Action {
return carapace.ActionExecCommand(cmd, args...)(func(output []byte) carapace.Action {
if string(output) == "" {
return carapace.ActionFiles()
}
Expand Down

0 comments on commit b2fb14a

Please sign in to comment.