-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathaws.go
More file actions
44 lines (40 loc) · 1.47 KB
/
Copy pathaws.go
File metadata and controls
44 lines (40 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package bridge
import (
"strings"
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace/pkg/style"
)
// ActionAws bridges https://github.com/aws/aws-cli
func ActionAws(command ...string) carapace.Action {
return actionCommand(command...)(func(command ...string) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if c.Value == "-" {
c.Value += "-" // no shorthand flags so expand to longhand first (which is needed for the completer)
}
c.Setenv("COMP_LINE", "aws "+strings.Join(append(c.Args, c.Value), " ")) // TODO escape/quote special characters
return carapace.ActionExecCommand("aws_completer")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
if lines[0] == "" {
return carapace.ActionValues()
}
for index, line := range lines {
if before, ok := strings.CutSuffix(line, " "); ok {
lines[index] = before // v1 has space suffix
}
}
a := carapace.ActionValues(lines[:len(lines)-1]...)
switch {
case strings.HasPrefix(c.Value, "file://"):
a = a.NoSpace('/').StyleF(func(s string, sc style.Context) string {
return style.ForPath(strings.TrimPrefix(s, "file://"), sc)
})
case strings.HasPrefix(c.Value, "fileb://"):
a = a.NoSpace('/').StyleF(func(s string, sc style.Context) string {
return style.ForPath(strings.TrimPrefix(s, "fileb://"), sc)
})
}
return a
}).Invoke(c).ToA()
})
})
}