Skip to content

Commit 1eafdbb

Browse files
authored
feat: migrate to github.com/urfave/cli/v3 (#287)
1 parent 10bcd21 commit 1eafdbb

22 files changed

+341
-579
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
go-version: [ "1.23", "1.24" ]
13+
go-version: [ "1.24" ]
1414
runs-on: ubuntu-latest
1515
env:
1616
GOLANGCI_LINT_VERSION: v2.0.2

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ linters:
3333
- wsl
3434
settings:
3535
cyclop:
36-
max-complexity: 12
36+
max-complexity: 15
37+
lll:
38+
line-length: 160
3739
exclusions:
3840
generated: lax

cmd.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

cmd_test.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

doc.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,5 @@
22
Package cmd implements cmd helpers.
33
44
This provides helpers on top of `github.com/urfave/cli`.
5-
6-
Example usage:
7-
8-
var c *cli.Context // Get this from your action
9-
10-
log, err := cmd.NewLogger(c)
11-
if err != nil {
12-
// Handle error.
13-
}
14-
15-
stats, err := cmd.NewStatter(c, log)
16-
if err != nil {
17-
// Handle error.
18-
}
195
*/
206
package cmd

example_test.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package cmd_test
22

33
import (
44
"context"
5-
"fmt"
65

7-
"github.com/hamba/cmd/v2"
8-
"github.com/urfave/cli/v2"
6+
"github.com/hamba/cmd/v3"
7+
"github.com/urfave/cli/v3"
98
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
109
)
1110

1211
func ExampleNewLogger() {
13-
var c *cli.Context // Get this from your action
12+
var c *cli.Command // Get this from your action
1413

1514
log, err := cmd.NewLogger(c)
1615
if err != nil {
@@ -22,7 +21,7 @@ func ExampleNewLogger() {
2221
}
2322

2423
func ExampleNewStatter() {
25-
var c *cli.Context // Get this from your action
24+
var c *cli.Command // Get this from your action
2625

2726
log, err := cmd.NewLogger(c)
2827
if err != nil {
@@ -35,13 +34,13 @@ func ExampleNewStatter() {
3534
// Handle error.
3635
return
3736
}
38-
defer stats.Close()
37+
defer func() { _ = stats.Close() }()
3938

4039
_ = stats
4140
}
4241

4342
func ExampleNewProfiler() {
44-
var c *cli.Context // Get this from your action
43+
var c *cli.Command // Get this from your action
4544

4645
log, err := cmd.NewLogger(c)
4746
if err != nil {
@@ -62,35 +61,26 @@ func ExampleNewProfiler() {
6261
}
6362

6463
func ExampleNewTracer() {
65-
var c *cli.Context // Get this from your action
64+
var (
65+
ctx context.Context
66+
c *cli.Command // Get this from your action
67+
)
6668

6769
log, err := cmd.NewLogger(c)
6870
if err != nil {
6971
// Handle error.
7072
return
7173
}
7274

73-
tracer, err := cmd.NewTracer(c, log,
75+
tracer, err := cmd.NewTracer(ctx, c, log,
7476
semconv.ServiceNameKey.String("my-service"),
7577
semconv.ServiceVersionKey.String("1.0.0"),
7678
)
7779
if err != nil {
7880
// Handle error.
7981
return
8082
}
81-
defer tracer.Shutdown(context.Background())
83+
defer func() { _ = tracer.Shutdown(context.Background()) }()
8284

8385
_ = tracer
8486
}
85-
86-
func ExampleSplit() {
87-
input := []string{"a=b", "foo=bar"} // Usually from a cli.StringSlice
88-
89-
tags, err := cmd.Split(input, "=")
90-
if err != nil {
91-
// Handle error
92-
}
93-
94-
fmt.Println(tags)
95-
// Output: [[a b] [foo bar]]
96-
}

flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"github.com/urfave/cli/v2"
4+
"github.com/urfave/cli/v3"
55
)
66

77
// Flags represents a set of CLI flags.

flags_test.go

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

6-
"github.com/hamba/cmd/v2"
6+
"github.com/hamba/cmd/v3"
77
"github.com/stretchr/testify/assert"
8-
"github.com/urfave/cli/v2"
8+
"github.com/urfave/cli/v3"
99
)
1010

1111
func TestFlags_Merge(t *testing.T) {

go.mod

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
module github.com/hamba/cmd/v2
1+
module github.com/hamba/cmd/v3
22

3-
go 1.23.0
3+
go 1.24.0
44

55
toolchain go1.24.1
66

77
require (
8+
github.com/ettle/strcase v0.2.0
89
github.com/fatih/color v1.18.0
910
github.com/grafana/otel-profiling-go v0.5.1
1011
github.com/grafana/pyroscope-go v1.2.1
1112
github.com/hamba/logger/v2 v2.8.0
1213
github.com/hamba/statter/v2 v2.6.0
1314
github.com/stretchr/testify v1.10.0
14-
github.com/urfave/cli/v2 v2.27.6
15+
github.com/urfave/cli/v3 v3.1.0
1516
go.opentelemetry.io/otel v1.35.0
1617
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0
1718
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0
@@ -26,7 +27,6 @@ require (
2627
github.com/cactus/go-statsd-client/v5 v5.1.0 // indirect
2728
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2829
github.com/cespare/xxhash/v2 v2.3.0 // indirect
29-
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
3030
github.com/davecgh/go-spew v1.1.1 // indirect
3131
github.com/go-logr/logr v1.4.2 // indirect
3232
github.com/go-logr/stdr v1.2.2 // indirect
@@ -45,11 +45,9 @@ require (
4545
github.com/prometheus/common v0.62.0 // indirect
4646
github.com/prometheus/procfs v0.15.1 // indirect
4747
github.com/puzpuzpuz/xsync v1.5.2 // indirect
48-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
4948
github.com/stretchr/objx v0.5.2 // indirect
5049
github.com/valyala/fastrand v1.1.0 // indirect
5150
github.com/valyala/histogram v1.2.0 // indirect
52-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
5351
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
5452
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.35.0 // indirect
5553
go.opentelemetry.io/otel/metric v1.35.0 // indirect

go.sum

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3
88
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
99
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
1010
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
11-
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
12-
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1311
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1412
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1513
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14+
github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q=
15+
github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A=
1616
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
1717
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
1818
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -74,8 +74,6 @@ github.com/puzpuzpuz/xsync v1.5.2 h1:yRAP4wqSOZG+/4pxJ08fPTwrfL0IzE/LKQ/cw509qGY
7474
github.com/puzpuzpuz/xsync v1.5.2/go.mod h1:K98BYhX3k1dQ2M63t1YNVDanbwUPmBCAhNmVrrxfiGg=
7575
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
7676
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
77-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
78-
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7977
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8078
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
8179
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -86,14 +84,12 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
8684
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
8785
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
8886
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
89-
github.com/urfave/cli/v2 v2.27.6 h1:VdRdS98FNhKZ8/Az8B7MTyGQmpIr36O1EHybx/LaZ4g=
90-
github.com/urfave/cli/v2 v2.27.6/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
87+
github.com/urfave/cli/v3 v3.1.0 h1:kQR+oiqpJkBAONxBjM4RWivD4AfPHL/f4vqe/gjYU8M=
88+
github.com/urfave/cli/v3 v3.1.0/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
9189
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
9290
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
9391
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
9492
github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY=
95-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
96-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
9793
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
9894
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
9995
go.opentelemetry.io/otel v1.21.0/go.mod h1:QZzNPQPm1zLX4gZK4cMi+71eaorMSGT3A4znnUvNNEo=

0 commit comments

Comments
 (0)