Skip to content

Commit 246f7e9

Browse files
authored
Merge pull request #141 from cantabular/urfave-cli-v3
Update to urfave/cli v3
2 parents ddc8dfe + 8310160 commit 246f7e9

5 files changed

Lines changed: 101 additions & 103 deletions

File tree

go.mod

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,5 @@ go 1.25.1
44

55
require (
66
github.com/gorilla/websocket v1.5.3
7-
github.com/urfave/cli/v2 v2.27.7
8-
)
9-
10-
require (
11-
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
12-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
13-
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
7+
github.com/urfave/cli/v3 v3.4.1
148
)

go.sum

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
2-
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
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=
33
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
44
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
5-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
6-
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7-
github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
8-
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
9-
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
10-
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
5+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
8+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
9+
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
10+
github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
11+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
12+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 85 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,118 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"log"
67
"net/http"
78
"net/url"
89
"os"
910
"regexp"
1011

11-
"github.com/urfave/cli/v2"
12+
"github.com/urfave/cli/v3"
1213

1314
"github.com/sensiblecodeio/hookbot/pkg/hookbot"
1415
"github.com/sensiblecodeio/hookbot/pkg/router/github"
1516
)
1617

1718
func main() {
18-
app := cli.NewApp()
19-
app.Name = "hookbot"
20-
app.Usage = "turn webhooks into websockets"
21-
app.Version = "0.16.0"
22-
23-
app.Flags = []cli.Flag{
24-
&cli.StringFlag{
25-
Name: "key",
26-
Usage: "secret known only for hookbot for URL access control",
27-
Value: "<unset>",
28-
EnvVars: []string{"HOOKBOT_KEY"},
29-
},
30-
&cli.StringFlag{
31-
Name: "github-secret",
32-
Usage: "secret known by github for signing messages",
33-
Value: "<unset>",
34-
EnvVars: []string{"HOOKBOT_GITHUB_SECRET"},
19+
cmd := cli.Command{
20+
Name: "hookbot",
21+
Usage: "turn webhooks into websockets",
22+
Version: "0.16.0",
23+
Flags: []cli.Flag{
24+
&cli.StringFlag{
25+
Name: "key",
26+
Usage: "secret known only for hookbot for URL access control",
27+
Value: "<unset>",
28+
Sources: cli.EnvVars("HOOKBOT_KEY"),
29+
},
30+
&cli.StringFlag{
31+
Name: "github-secret",
32+
Usage: "secret known by github for signing messages",
33+
Value: "<unset>",
34+
Sources: cli.EnvVars("HOOKBOT_GITHUB_SECRET"),
35+
},
3536
},
36-
}
3737

38-
app.Commands = []*cli.Command{
39-
{
40-
Name: "serve",
41-
Usage: "start a hookbot instance, listening on http",
42-
Action: ActionServe,
43-
Flags: []cli.Flag{
44-
&cli.StringFlag{
45-
Name: "bind, b",
46-
Value: ":8080",
47-
Usage: "address to listen on",
48-
},
49-
&cli.StringFlag{
50-
Name: "sslkey, k",
51-
Value: "<unset>",
52-
Usage: "path to the SSL secret key",
53-
},
54-
&cli.StringFlag{
55-
Name: "sslcrt, c",
56-
Value: "<unset>",
57-
Usage: "path to the SSL compound certificate",
58-
},
59-
&cli.StringSliceFlag{
60-
Name: "router",
61-
Value: cli.NewStringSlice(""),
62-
Usage: "list of routers to enable",
38+
Commands: []*cli.Command{
39+
{
40+
Name: "serve",
41+
Usage: "start a hookbot instance, listening on http",
42+
Action: ActionServe,
43+
Flags: []cli.Flag{
44+
&cli.StringFlag{
45+
Name: "bind, b",
46+
Value: ":8080",
47+
Usage: "address to listen on",
48+
},
49+
&cli.StringFlag{
50+
Name: "sslkey, k",
51+
Value: "<unset>",
52+
Usage: "path to the SSL secret key",
53+
},
54+
&cli.StringFlag{
55+
Name: "sslcrt, c",
56+
Value: "<unset>",
57+
Usage: "path to the SSL compound certificate",
58+
},
59+
&cli.StringSliceFlag{
60+
Name: "router",
61+
Usage: "list of routers to enable",
62+
},
6363
},
6464
},
65-
},
66-
{
67-
Name: "make-tokens",
68-
Aliases: []string{"t"},
69-
Usage: "given a list of URIs, generate tokens one per line",
70-
Action: ActionMakeTokens,
71-
Flags: []cli.Flag{
72-
&cli.BoolFlag{
73-
Name: "bare",
74-
Usage: "print only tokens (not as basic-auth URLs)",
75-
},
76-
&cli.StringFlag{
77-
Name: "url-base, U",
78-
Value: "http://localhost:8080",
79-
Usage: "base URL to generate for (not included in hmac)",
80-
EnvVars: []string{"HOOKBOT_URL_BASE"},
65+
{
66+
Name: "make-tokens",
67+
Aliases: []string{"t"},
68+
Usage: "given a list of URIs, generate tokens one per line",
69+
Action: ActionMakeTokens,
70+
Flags: []cli.Flag{
71+
&cli.BoolFlag{
72+
Name: "bare",
73+
Usage: "print only tokens (not as basic-auth URLs)",
74+
},
75+
&cli.StringFlag{
76+
Name: "url-base, U",
77+
Value: "http://localhost:8080",
78+
Usage: "base URL to generate for (not included in hmac)",
79+
Sources: cli.EnvVars("HOOKBOT_URL_BASE"),
80+
},
8181
},
8282
},
83-
},
84-
{
85-
Name: "route-github",
86-
Usage: "route github requests",
87-
Action: github.ActionRoute,
88-
Flags: []cli.Flag{
89-
&cli.StringFlag{
90-
Name: "monitor-url, u",
91-
Usage: "URL to monitor",
92-
},
93-
&cli.StringFlag{
94-
Name: "origin",
95-
Value: "samehost",
96-
Usage: "URL to use for the origin header ('samehost' is special)",
97-
EnvVars: []string{"HOOKBOT_ORIGIN"},
98-
},
99-
&cli.StringSliceFlag{
100-
Name: "header, H",
101-
Usage: "headers to pass to the remote",
102-
Value: cli.NewStringSlice(""),
103-
EnvVars: []string{"HOOKBOT_HEADER"},
83+
{
84+
Name: "route-github",
85+
Usage: "route github requests",
86+
Action: github.ActionRoute,
87+
Flags: []cli.Flag{
88+
&cli.StringFlag{
89+
Name: "monitor-url, u",
90+
Usage: "URL to monitor",
91+
},
92+
&cli.StringFlag{
93+
Name: "origin",
94+
Value: "samehost",
95+
Usage: "URL to use for the origin header ('samehost' is special)",
96+
Sources: cli.EnvVars("HOOKBOT_ORIGIN"),
97+
},
98+
&cli.StringSliceFlag{
99+
Name: "header, H",
100+
Usage: "headers to pass to the remote",
101+
Sources: cli.EnvVars("HOOKBOT_HEADER"),
102+
},
104103
},
105104
},
106105
},
107106
}
108107

109-
app.RunAndExitOnError()
108+
if err := cmd.Run(context.Background(), os.Args); err != nil {
109+
log.Fatal(err)
110+
}
110111
}
111112

112113
var SubscribeURIRE = regexp.MustCompile("^(?:/unsafe)?/sub")
113114

114-
func ActionMakeTokens(c *cli.Context) error {
115+
func ActionMakeTokens(_ context.Context, c *cli.Command) error {
115116
key := c.String("key")
116117
if key == "<unset>" {
117118
log.Fatalln("HOOKBOT_KEY not set")
@@ -181,7 +182,7 @@ func ActionMakeTokens(c *cli.Context) error {
181182
return nil
182183
}
183184

184-
func ActionServe(c *cli.Context) error {
185+
func ActionServe(_ context.Context, c *cli.Command) error {
185186
key := c.String("key")
186187
if key == "<unset>" {
187188
log.Fatalln("HOOKBOT_KEY not set")

pkg/hookbot/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package hookbot
33
import (
44
"log"
55

6-
"github.com/urfave/cli/v2"
6+
"github.com/urfave/cli/v3"
77
)
88

99
type Router interface {
@@ -18,7 +18,7 @@ func RegisterRouter(router Router) {
1818
availableRouters = append(availableRouters, router)
1919
}
2020

21-
func ConfigureRouters(c *cli.Context, h *Hookbot) {
21+
func ConfigureRouters(c *cli.Command, h *Hookbot) {
2222
enabledRouters := map[string]struct{}{}
2323

2424
for _, r := range c.StringSlice("router") {

pkg/router/github/github.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/json"
67
"fmt"
78
"io/ioutil"
@@ -11,7 +12,7 @@ import (
1112
"regexp"
1213
"strings"
1314

14-
"github.com/urfave/cli/v2"
15+
"github.com/urfave/cli/v3"
1516

1617
"github.com/sensiblecodeio/hookbot/pkg/hookbot"
1718
"github.com/sensiblecodeio/hookbot/pkg/listen"
@@ -57,7 +58,7 @@ func MustMakeHeader(
5758
return header
5859
}
5960

60-
func ActionRoute(c *cli.Context) error {
61+
func ActionRoute(_ context.Context, c *cli.Command) error {
6162

6263
target, err := url.Parse(c.String("monitor-url"))
6364
if err != nil {

0 commit comments

Comments
 (0)