Skip to content

Commit 2d324c0

Browse files
rsteubevalorl
andauthored
urfavecliV3 (#254)
* add support for urfavecli/v3 The existing bridge cannot be used with v3, as it exposes `--generate-shell-completion` instead of `--generate-bash-completion` * urfavecli: rebased and added compose service --------- Co-authored-by: valorl <11498571+valorl@users.noreply.github.com>
1 parent 88cc9a6 commit 2d324c0

12 files changed

Lines changed: 133 additions & 6 deletions

File tree

.docker/urfavecli.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ services:
33
build:
44
context: urfavecli
55
image: ghcr.io/carapace-sh/carapace-bridge:urfavecli
6-
hostname: carapace-bridge:urfavecli_tea
6+
hostname: carapace-bridge:urfavecli_greet
77
volumes:
88
- '..:/carapace-bridge:ro'

.docker/urfavecli/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
FROM alpine
2-
3-
RUN apk add --no-cache curl libc6-compat tea
1+
FROM golang
42

53
RUN curl -so - https://dl.elv.sh/linux-amd64/elvish-v0.21.0.tar.gz | tar -xzvC /usr/local/bin
64

5+
ADD greet /greet
6+
7+
RUN cd /greet && go install
8+
79
RUN mkdir -p ~/.config/elvish \
8-
&& echo -e "set paths = [ /carapace-bridge/cmd/carapace-bridge \$@paths ]\neval (carapace-bridge _carapace|slurp)\neval (carapace-bridge urfavecli tea|slurp)" > ~/.config/elvish/rc.elv
10+
&& echo "set paths = [ /carapace-bridge/cmd/carapace-bridge \$@paths ]\neval (carapace-bridge _carapace|slurp)\neval (carapace-bridge urfavecli greet|slurp)" > ~/.config/elvish/rc.elv
911
ENV PATH="/carapace-bridge/cmd/carapace-bridge:$PATH"
1012

1113
ENTRYPOINT /usr/local/bin/elvish

.docker/urfavecli/greet/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/carapace-sh/carapace-bridge/.docker/urfavecli/greet
2+
3+
go 1.23.4
4+
5+
require github.com/urfave/cli/v3 v3.3.8

.docker/urfavecli/greet/go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
6+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7+
github.com/urfave/cli/v3 v3.3.8 h1:BzolUExliMdet9NlJ/u4m5vHSotJ3PzEqSAZ1oPMa/E=
8+
github.com/urfave/cli/v3 v3.3.8/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

.docker/urfavecli/greet/main.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"os"
8+
9+
"github.com/urfave/cli/v3"
10+
)
11+
12+
func main() {
13+
cmd := &cli.Command{
14+
Name: "greet",
15+
EnableShellCompletion: true,
16+
Commands: []*cli.Command{
17+
{
18+
Name: "add",
19+
Aliases: []string{"a"},
20+
Usage: "add a task to the list",
21+
Action: func(ctx context.Context, cmd *cli.Command) error {
22+
fmt.Println("added task: ", cmd.Args().First())
23+
return nil
24+
},
25+
},
26+
{
27+
Name: "complete",
28+
Aliases: []string{"c"},
29+
Usage: "complete a task on the list",
30+
Action: func(ctx context.Context, cmd *cli.Command) error {
31+
fmt.Println("completed task: ", cmd.Args().First())
32+
return nil
33+
},
34+
},
35+
{
36+
Name: "template",
37+
Aliases: []string{"t"},
38+
Usage: "options for task templates",
39+
Commands: []*cli.Command{
40+
{
41+
Name: "add",
42+
Usage: "add a new template",
43+
Action: func(ctx context.Context, cmd *cli.Command) error {
44+
fmt.Println("new task template: ", cmd.Args().First())
45+
return nil
46+
},
47+
},
48+
{
49+
Name: "remove",
50+
Usage: "remove an existing template",
51+
Action: func(ctx context.Context, cmd *cli.Command) error {
52+
fmt.Println("removed task template: ", cmd.Args().First())
53+
return nil
54+
},
55+
},
56+
},
57+
},
58+
},
59+
}
60+
61+
if err := cmd.Run(context.Background(), os.Args); err != nil {
62+
log.Fatal(err)
63+
}
64+
}

.docker/urfavecliV1.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
urfavecliV1:
3+
build:
4+
context: urfavecliV1
5+
image: ghcr.io/carapace-sh/carapace-bridge:urfavecliV1
6+
hostname: carapace-bridge:urfavecliV1_tea
7+
volumes:
8+
- '..:/carapace-bridge:ro'

.docker/urfavecliV1/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine
2+
3+
RUN apk add --no-cache curl libc6-compat tea
4+
5+
RUN curl -so - https://dl.elv.sh/linux-amd64/elvish-v0.21.0.tar.gz | tar -xzvC /usr/local/bin
6+
7+
RUN mkdir -p ~/.config/elvish \
8+
&& echo -e "set paths = [ /carapace-bridge/cmd/carapace-bridge \$@paths ]\neval (carapace-bridge _carapace|slurp)\neval (carapace-bridge urfavecli@v1 tea|slurp)" > ~/.config/elvish/rc.elv
9+
ENV PATH="/carapace-bridge/cmd/carapace-bridge:$PATH"
10+
11+
ENTRYPOINT /usr/local/bin/elvish

cmd/carapace-bridge/cmd/root.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func Execute(version string) error {
3535
rootCmd.Version = version
3636
return rootCmd.Execute()
3737
}
38+
3839
func init() {
3940
carapace.Gen(rootCmd)
4041
rootCmd.AddGroup(&cobra.Group{ID: "bridge", Title: "Bridge Commands"})
@@ -52,7 +53,8 @@ func init() {
5253
addSubCommand("kingpin", "bridges https://github.com/alecthomas/kingpin", bridge.ActionKingpin)
5354
addSubCommand("macro", "bridges macros exposed with https://github.com/carapace-sh/carapace-spec", bridge.ActionMacro)
5455
addSubCommand("powershell", "bridges completions registered in powershell", bridge.ActionPowershell)
55-
addSubCommand("urfavecli", "bridges https://github.com/urfave/cli", bridge.ActionUrfavecli)
56+
addSubCommand("urfavecli", "bridges https://github.com/urfave/cli (v2)", bridge.ActionUrfavecli)
57+
addSubCommand("urfavecli@v1", "bridges https://github.com/urfave/cli (v3)", bridge.ActionUrfavecliV1)
5658
addSubCommand("yargs", "bridges https://github.com/yargs/yargs", bridge.ActionYargs)
5759
addSubCommand("zsh", "bridges completions registered in zsh", bridge.ActionZsh)
5860
}

compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ include:
55
- ./.docker/complete.yaml
66
- ./.docker/kingpin.yaml
77
- ./.docker/urfavecli.yaml
8+
- ./.docker/urfavecliV1.yaml
89
- ./.docker/yargs.yaml

pkg/actions/bridge/bridge.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var bridgeActions = map[string]func(command ...string) carapace.Action{
2222
"kingpin": ActionKingpin,
2323
"powershell": ActionPowershell,
2424
"urfavecli": ActionUrfavecli,
25+
"urfavecli@v1": ActionUrfavecliV1,
2526
"yargs": ActionYargs,
2627
"zsh": ActionZsh,
2728
}

0 commit comments

Comments
 (0)