Skip to content

Commit

Permalink
updated carapace to v0.30.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 2, 2023
1 parent a267347 commit 9f613df
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 79 deletions.
2 changes: 1 addition & 1 deletion completers/bat_completer/cmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func ActionLanguages() carapace.Action {
if len(splitted) == 1 {
values = append(values, splitted[0], "", style.Default)
} else if len(splitted) > 1 {
values = append(values, splitted[0], splitted[1], style.ForPathExt("."+strings.SplitN(splitted[1], ",", 2)[0]))
values = append(values, splitted[0], splitted[1], style.ForPathExt("."+strings.SplitN(splitted[1], ",", 2)[0], c))
}
}
return carapace.ActionStyledValuesDescribed(values...)
Expand Down
4 changes: 2 additions & 2 deletions completers/deno_completer/cmd/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func init() {

carapace.Gen(fmtCmd).FlagCompletion(carapace.ActionMap{
"config": carapace.ActionFiles(),
"ext": carapace.ActionValues("ts", "tsx", "js", "jsx", "md", "json", "jsonc").StyleF(func(s string) string {
return style.ForPathExt("." + s)
"ext": carapace.ActionValues("ts", "tsx", "js", "jsx", "md", "json", "jsonc").StyleF(func(s string, sc style.Context) string {
return style.ForPathExt("."+s, sc)
}),
"options-prose-wrap": carapace.ActionValues("always", "never", "preserve").StyleF(style.ForKeyword),
})
Expand Down
4 changes: 2 additions & 2 deletions completers/http_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func ActionRequestItem() carapace.Action {

headers := http.ActionRequestHeaderNames().Invoke(c).Suffix(":") // use full context
return carapace.ActionMultiParts("", func(c carapace.Context) carapace.Action {
return ActionSeparators()
return ActionSeparators().Style(style.Blue)
}).Invoke(context).Merge(headers).ToA()
})
}
Expand All @@ -238,5 +238,5 @@ func ActionSeparators() carapace.Action {
"@", "Form file fields (only with --form or --multipart)",
"=@", "A data field like '=', but takes a file path and embeds its content",
":=@", "A raw JSON field like ':=', but takes a file path and embeds its content",
)
).Tag("separators")
}
4 changes: 2 additions & 2 deletions completers/inkscape_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func init() {
"display": os.ActionDisplays(),
"export-filename": carapace.ActionFiles(),
"export-pdf-version": carapace.ActionValues("1.4", "1.5"),
"export-type": carapace.ActionValues("svg", "png", "ps", "eps", "pdf", "emf", "wmf", "xaml").StyleF(func(s string) string {
return style.ForPathExt("." + s)
"export-type": carapace.ActionValues("svg", "png", "ps", "eps", "pdf", "emf", "wmf", "xaml").StyleF(func(s string, sc style.Context) string {
return style.ForPathExt("."+s, sc)
}),
})

Expand Down
4 changes: 2 additions & 2 deletions completers/lncrawl_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func init() {
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"crawler": carapace.ActionFiles(),
"filename": carapace.ActionFiles(),
"format": carapace.ActionValues("json", "epub", "text", "web", "docx", "mobi", "pdf", "rtf", "txt", "azw3", "fb2", "lit", "lrf", "oeb", "pdb", "rb", "snb", "tcr").StyleF(func(s string) string {
return style.ForPathExt("." + s)
"format": carapace.ActionValues("json", "epub", "text", "web", "docx", "mobi", "pdf", "rtf", "txt", "azw3", "fb2", "lit", "lrf", "oeb", "pdb", "rb", "snb", "tcr").StyleF(func(s string, sc style.Context) string {
return style.ForPathExt("."+s, sc)
}),
"output": carapace.ActionDirectories(),
})
Expand Down
2 changes: 2 additions & 0 deletions completers/mkdir_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().BoolS("Z", "Z", false, "set SELinux security context of each created directory to the default type")
rootCmd.Flags().String("context", "", "like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX")
rootCmd.Flags().Bool("help", false, "display this help and exit")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/pelletier/go-toml v1.9.5
github.com/rsteube/carapace v0.29.4
github.com/rsteube/carapace v0.30.0
github.com/rsteube/carapace-spec v0.3.1
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rsteube/carapace v0.29.4 h1:rSqXBvfGYflAMJLFRbZpf6HicweNL5w6iA3n0Znd2yE=
github.com/rsteube/carapace v0.29.4/go.mod h1:/ALYHicIpak6TjQnKl7HupclqJydy2LQb6CkawYBxDo=
github.com/rsteube/carapace v0.30.0 h1:tJjVNqz1eBZPvMyFcSwCyncNgcTYy0bI/xZnOidX59U=
github.com/rsteube/carapace v0.30.0/go.mod h1:/ALYHicIpak6TjQnKl7HupclqJydy2LQb6CkawYBxDo=
github.com/rsteube/carapace-pflag v0.0.4 h1:Onb0cLNLxg1xJr2EsMlBldAI5KkybrvZ89b5cRElZXI=
github.com/rsteube/carapace-pflag v0.0.4/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/rsteube/carapace-spec v0.3.1 h1:kAl7Iu9ALJ32W/5mo64rmrfgjaIR1J58Z6xw887dFZo=
Expand Down
6 changes: 3 additions & 3 deletions pkg/actions/fs/blockdevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func ActionBlockDevices() carapace.Action {
return actionBlockdevices(func(blockdevices []blockdevice) carapace.Action {
vals := make([]string, 0)
for _, b := range blockdevices {
vals = append(vals, b.Path, fmt.Sprintf("%v %v", b.Size, b.Parttypename), style.ForPath(b.Path))
vals = append(vals, b.Path, fmt.Sprintf("%v %v", b.Size, b.Parttypename))
}
return carapace.ActionStyledValuesDescribed(vals...)
})
return carapace.ActionValuesDescribed(vals...).StyleF(style.ForPath)
}).Tag("block devices")
}

// TODO add examples to actions
Expand Down
4 changes: 2 additions & 2 deletions pkg/actions/fs/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ func ActionFilenameExtensions() carapace.Action {
"zip", "Zip (file format)",
"zrx", "REXX scripting language for ZOC_(software)",
"zs", "Script for Minecraft mod MineTweaker and CraftTweaker",
).StyleF(func(s string) string {
return style.ForPathExt("." + s)
).StyleF(func(s string, sc style.Context) string {
return style.ForPathExt("."+s, sc)
})
}
2 changes: 1 addition & 1 deletion pkg/actions/fs/jar.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ActionJarFileClasses(file string) carapace.Action {
vals = append(vals, name)
}
}
return carapace.ActionValues(vals...).Style(style.ForPathExt(".class"))
return carapace.ActionValues(vals...).Style(style.ForPathExt(".class", c))
}
})
}
66 changes: 33 additions & 33 deletions pkg/actions/net/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ActionRequestHeaderNames() carapace.Action {
"Upgrade", "Ask the server to upgrade to another protocol. Must not be used in HTTP/2.[13]",
"Via", "Informs the server of proxies through which the request was sent.",
"Warning", "A general warning about possible problems with the entity body.",
)
).Tag("request headers")
}

// ActionRequestHeaderValues completes values for given request header
Expand Down Expand Up @@ -111,41 +111,41 @@ func ActionRequestHeaderValues(header string) carapace.Action {
func ActionMediaTypes() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return carapace.ActionStyledValues(
"application/x-executable", style.ForPathExt(".exe"),
"application/x-executable", style.ForPathExt(".exe", c),
"application/graphql", style.Default,
"application/javascript", style.ForPathExt(".js"),
"application/json", style.ForPathExt(".json"),
"application/ld+json", style.ForPathExt(".json"),
"application/msword", style.ForPathExt(".docx"),
"application/pdf", style.ForPathExt(".pdf"),
"application/sql", style.ForPathExt(".sql"),
"application/vnd.api+json", style.ForPathExt(".json"),
"application/vnd.ms-excel", style.ForPathExt(".xslx"),
"application/vnd.ms-powerpoint", style.ForPathExt(".pptx"),
"application/vnd.oasis.opendocument.text", style.ForPathExt(".odt"),
"application/vnd.openxmlformats-officedocument.presentationml.presentation", style.ForPathExt(".odp"),
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", style.ForPathExt(".ods"),
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", style.ForPathExt(".odt"),
"application/javascript", style.ForPathExt(".js", c),
"application/json", style.ForPathExt(".json", c),
"application/ld+json", style.ForPathExt(".json", c),
"application/msword", style.ForPathExt(".docx", c),
"application/pdf", style.ForPathExt(".pdf", c),
"application/sql", style.ForPathExt(".sql", c),
"application/vnd.api+json", style.ForPathExt(".json", c),
"application/vnd.ms-excel", style.ForPathExt(".xslx", c),
"application/vnd.ms-powerpoint", style.ForPathExt(".pptx", c),
"application/vnd.oasis.opendocument.text", style.ForPathExt(".odt", c),
"application/vnd.openxmlformats-officedocument.presentationml.presentation", style.ForPathExt(".odp", c),
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", style.ForPathExt(".ods", c),
"application/vnd.openxmlformats-officedocument.wordprocessingml.document", style.ForPathExt(".odt", c),
"application/x-www-form-urlencoded", style.Default,
"application/xml", style.ForPathExt(".xml"),
"application/zip", style.ForPathExt(".zip"),
"application/zstd", style.ForPathExt(".zstd"),
"audio/mpeg", style.ForPathExt(".mpeg"),
"audio/ogg", style.ForPathExt(".ogg"),
"image/gif", style.ForPathExt(".gif"),
"image/apng", style.ForPathExt(".apng"),
"image/flif", style.ForPathExt(".flif"),
"image/webp", style.ForPathExt(".webp"),
"image/x-mng", style.ForPathExt(".x-mng"),
"image/jpeg", style.ForPathExt(".jpeg"),
"image/png", style.ForPathExt(".png"),
"application/xml", style.ForPathExt(".xml", c),
"application/zip", style.ForPathExt(".zip", c),
"application/zstd", style.ForPathExt(".zstd", c),
"audio/mpeg", style.ForPathExt(".mpeg", c),
"audio/ogg", style.ForPathExt(".ogg", c),
"image/gif", style.ForPathExt(".gif", c),
"image/apng", style.ForPathExt(".apng", c),
"image/flif", style.ForPathExt(".flif", c),
"image/webp", style.ForPathExt(".webp", c),
"image/x-mng", style.ForPathExt(".x-mng", c),
"image/jpeg", style.ForPathExt(".jpeg", c),
"image/png", style.ForPathExt(".png", c),
"multipart/form-data", style.Default,
"text/css", style.ForPathExt(".css"),
"text/csv", style.ForPathExt(".csv"),
"text/html", style.ForPathExt(".html"),
"text/php", style.ForPathExt(".php"),
"text/plain", style.ForPathExt(".txt"),
"text/xml", style.ForPathExt(".xml"),
"text/css", style.ForPathExt(".css", c),
"text/csv", style.ForPathExt(".csv", c),
"text/html", style.ForPathExt(".html", c),
"text/php", style.ForPathExt(".php", c),
"text/plain", style.ForPathExt(".txt", c),
"text/xml", style.ForPathExt(".xml", c),
)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/actions/net/http/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ func ActionRequestMethods() carapace.Action {
"PUT", "Replace all current representations of the target resource", styles.CarapaceBin.HttpMethodPUT,
"TRACE", "Perform a message loop-back test along the path to the target resource", styles.CarapaceBin.HttpMethodTRACE,
)
})
}).Tag("request methods")
}
3 changes: 2 additions & 1 deletion pkg/actions/net/http/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package http
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/styles"
"github.com/rsteube/carapace/pkg/style"
)

// ActionStatusCodes completes http status codes
Expand Down Expand Up @@ -68,7 +69,7 @@ func ActionStatusCodes() carapace.Action {
"508", "Loop Detected",
"510", "Not Extended",
"511", "Network Authentication Required",
).StyleF(func(s string) string {
).StyleF(func(s string, _ style.Context) string {
switch []rune(s)[0] {
case '1':
return styles.CarapaceBin.HttpStatusInformational
Expand Down
18 changes: 9 additions & 9 deletions pkg/actions/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// pihole
func ActionHosts() carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
vals := []string{}
batch := carapace.Batch()
if file, err := c.Abs("~/.ssh/known_hosts"); err == nil {
if content, err := os.ReadFile(file); err == nil {
r := regexp.MustCompile(`^(?P<host>[^ ,#]+)`)
Expand All @@ -26,19 +26,19 @@ func ActionHosts() carapace.Action {
for _, entry := range strings.Split(string(content), "\n") {
if r.MatchString(entry) {
if host := r.FindStringSubmatch(entry)[0]; rIPv4.MatchString(host) {
vals = append(vals, host, style.Default)
batch = append(batch, carapace.ActionStyledValues(host, style.Default).Tag("ipv4 addresses"))
} else if rIPv6.MatchString(host) {
vals = append(vals, host, style.Bold)
batch = append(batch, carapace.ActionStyledValues(host, style.Bold).Tag("ipv6 addresses"))
} else {
vals = append(vals, host, style.Blue)
batch = append(batch, carapace.ActionStyledValues(host, style.Blue).Tag("hostnames"))
}
}
}
} else {
return carapace.ActionMessage(err.Error())
}
}
return carapace.ActionStyledValues(vals...)
return batch.ToA()
})
}

Expand Down Expand Up @@ -144,7 +144,7 @@ func ActionDevices(includedDevices IncludedDevices) carapace.Action {
})
}
return carapace.ActionMessage("neither nmcli nor ifconfig available")
})
}).Tag("network devices")
}

// ActionConnections completes stored network connections
Expand All @@ -163,7 +163,7 @@ func ActionConnections() carapace.Action {
}
return carapace.ActionValuesDescribed(vals...)
})
})
}).Tag("network connections")
}

// ActionBssids completes BSSID's of local wifi networks
Expand All @@ -185,7 +185,7 @@ func ActionBssids() carapace.Action {
}
return carapace.ActionStyledValuesDescribed(vals...)
})
})
}).Tag("bssids")
}

// ActionSsids completes SSID's of local wifi networks
Expand All @@ -207,7 +207,7 @@ func ActionSsids() carapace.Action {
}
return carapace.ActionStyledValuesDescribed(vals...)
})
})
}).Tag("ssids")
}

func styleForBars(s string) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/actions/os/executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func actionDirectoryExecutables(dir string, prefix string, manDescriptions map[s
if description == "" {
description = manDescriptions[f.Name()]
}
vals = append(vals, f.Name(), description, style.ForPath(dir+"/"+f.Name()))
vals = append(vals, f.Name(), description, style.ForPath(dir+"/"+f.Name(), c))
}
}
}
Expand Down
24 changes: 13 additions & 11 deletions pkg/actions/tools/docker/compose/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,20 @@ func (o ContainerOpts) includeState(s string) bool {
// carapace-bin-bash-1 (exited)
// carapace-bin-elvish-1 (running)
func ActionContainers(opts ContainerOpts) carapace.Action {
return actionExecCompose(opts.Files, "ps", "--format", "json", "--all")(func(output []byte) carapace.Action {
var containers []container
if err := json.Unmarshal(output, &containers); err != nil {
return carapace.ActionMessage(err.Error())
}
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return actionExecCompose(opts.Files, "ps", "--format", "json", "--all")(func(output []byte) carapace.Action {
var containers []container
if err := json.Unmarshal(output, &containers); err != nil {
return carapace.ActionMessage(err.Error())
}

vals := make([]string, 0)
for _, c := range containers {
if opts.includeState(c.State) {
vals = append(vals, c.Name, c.State, style.ForKeyword(c.State))
vals := make([]string, 0)
for _, container := range containers {
if opts.includeState(container.State) {
vals = append(vals, container.Name, container.State, style.ForKeyword(container.State, c))
}
}
}
return carapace.ActionStyledValuesDescribed(vals...)
return carapace.ActionStyledValuesDescribed(vals...)
})
})
}
2 changes: 1 addition & 1 deletion pkg/actions/tools/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func ActionContainerPath() carapace.Action {

vals := make([]string, 0)
for _, path := range lines[:len(lines)-1] {
vals = append(vals, path, style.ForPathExt(path))
vals = append(vals, path, style.ForPathExt(path, c))
}
return carapace.ActionStyledValues(vals...)
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/actions/tools/gh/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func ActionContents(opts ContentOpts) carapace.Action {
if content.Type == "dir" {
name = content.Name + "/"
}
vals = append(vals, name, style.ForPathExt(name))
vals = append(vals, name, style.ForPathExt(name, c))
}
return carapace.ActionStyledValues(vals...)
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/actions/tools/git/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func ActionChanges(opts ChangeOpts) carapace.Action {
return carapace.ActionMessage(err.Error())
} else {
if status := line[:2]; strings.Contains(status, "D") { // deleted
untracked = append(untracked, relativePath, status, style.ForPathExt(relativePath))
untracked = append(untracked, relativePath, status, style.ForPathExt(relativePath, c))
} else {
untracked = append(untracked, relativePath, status, style.ForPath(relativePath))
untracked = append(untracked, relativePath, status, style.ForPath(relativePath, c))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/styles/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func init() {
style.Register("gh", &Gh)
}

func (_gh *gh) ForState(s string) string {
func (_gh *gh) ForState(s string, _ style.Context) string {
switch s {
case "closed":
return _gh.StateClosed
Expand Down

0 comments on commit 9f613df

Please sign in to comment.