Skip to content

Commit ab2d08c

Browse files
authored
fix(deps): complete urfave/cli v2 to v3 migration (#29)
* fix(deps): complete urfave/cli v2 to v3 migration PR #26 bumped go.mod to cli/v3 but left all code on v2. Migrate the CLI to v3: App -> Command, context-aware Action/Before/CommandNotFound, EnvVars -> Sources, drop removed PathFlag. Tidy drops unused v2. * ci(renovate): gate gomod major upgrades behind dashboard approval Major Go module bumps change the import path and break the API, so they need a manual code migration (cf. the cli/v2->v3 work in this branch). Require Dependency Dashboard approval so renovate surfaces them without auto-opening an uncompilable PR.
1 parent 0d7ca86 commit ab2d08c

8 files changed

Lines changed: 40 additions & 56 deletions

File tree

go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,18 @@ require (
77
github.com/sirupsen/logrus v1.9.4
88
github.com/stackitcloud/stackit-sdk-go/core v0.26.0
99
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.2
10-
github.com/urfave/cli/v2 v2.27.7
1110
github.com/urfave/cli/v3 v3.9.0
1211
gopkg.in/yaml.v3 v3.0.1
1312
)
1413

1514
require (
16-
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
1715
github.com/fatih/color v1.18.0 // indirect
1816
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
1917
github.com/google/uuid v1.6.0 // indirect
2018
github.com/mattn/go-colorable v0.1.13 // indirect
2119
github.com/mattn/go-isatty v0.0.20 // indirect
2220
github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4 // indirect
23-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
2421
github.com/stevenle/topsort v0.2.0 // indirect
25-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
2622
golang.org/x/sync v0.14.0 // indirect
2723
golang.org/x/sys v0.25.0 // indirect
2824
)

go.sum

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
2-
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
3-
github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo=
4-
github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
5-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
61
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
72
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
83
github.com/ekristen/libnuke v1.3.0 h1:HX9FcsmzwA0sWOuaaXUmKnuEgf/5ONwxTDhNJUhElvc=
@@ -30,41 +25,26 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
3025
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
3126
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3227
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
33-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
34-
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
35-
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
36-
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
3728
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
3829
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
3930
github.com/stackitcloud/stackit-sdk-go/core v0.26.0 h1:jQEb9gkehfp6VCP6TcYk7BI10cz4l0KM2L6hqYBH2QA=
4031
github.com/stackitcloud/stackit-sdk-go/core v0.26.0/go.mod h1:WU1hhxnjXw2EV7CYa1nlEvNpMiRY6CvmIOaHuL3pOaA=
41-
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.11.1 h1:HcKqjwIjv4OAW1aWI0U/JWjnzTwzSvdr6DLasH940EU=
42-
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.11.1/go.mod h1:Ts06id0KejUlQWbpR+/rm+tKng6QkTuFV1VQTPJ4dA4=
4332
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.2 h1:hWtbUy0UOhw1cE1riCNjvtmbF3zDl717DIcpEEMF9ps=
4433
github.com/stackitcloud/stackit-sdk-go/services/iaas v1.12.2/go.mod h1:AbPN9BGkdjc+tVsXEX9Vr8BPDjdlDmG26K1FwCKZQVU=
4534
github.com/stevenle/topsort v0.2.0 h1:LLWgtp34HPX6/RBDRS0kElVxGOTzGBLI1lSAa5Lb46k=
4635
github.com/stevenle/topsort v0.2.0/go.mod h1:ck2WG2/ZrOr6dLApQ/5Xrqy5wv3T0qhKYWE7r9tkibc=
47-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
48-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
49-
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
50-
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
51-
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
52-
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
53-
github.com/urfave/cli/v2 v2.27.7 h1:bH59vdhbjLv3LAvIu6gd0usJHgoTTPhCFib8qqOwXYU=
54-
github.com/urfave/cli/v2 v2.27.7/go.mod h1:CyNAG/xg+iAOg0N4MPGZqVmv2rCoP267496AOXUZjA4=
36+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
37+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
38+
github.com/urfave/cli/v3 v3.9.0 h1:AV9lIiPv3ukYnxunaCUsHnEozptYmDN2F0+yWqLMn/c=
5539
github.com/urfave/cli/v3 v3.9.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
56-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
57-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
5840
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
5941
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
60-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6142
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6243
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6344
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
6445
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
6546
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6647
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
6748
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
68-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6949
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
7050
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package main
22

33
import (
4+
"context"
45
"os"
56
"path"
67

78
"github.com/sirupsen/logrus"
8-
"github.com/urfave/cli/v2"
9+
"github.com/urfave/cli/v3"
910

1011
"github.com/qaiser42/stackit-nuke/pkg/common"
1112

@@ -25,20 +26,18 @@ func main() {
2526
}
2627
}()
2728

28-
app := cli.NewApp()
29-
app.Name = path.Base(os.Args[0])
30-
app.Usage = "remove all resources from a STACKIT project"
31-
app.Version = common.AppVersion.Summary
32-
app.Authors = []*cli.Author{
33-
{Name: "stackit-nuke contributors"},
29+
cmd := &cli.Command{
30+
Name: path.Base(os.Args[0]),
31+
Usage: "remove all resources from a STACKIT project",
32+
Version: common.AppVersion.Summary,
33+
Authors: []any{"stackit-nuke contributors"},
34+
Commands: common.GetCommands(),
35+
CommandNotFound: func(_ context.Context, _ *cli.Command, command string) {
36+
logrus.Fatalf("Command %s not found.", command)
37+
},
3438
}
3539

36-
app.Commands = common.GetCommands()
37-
app.CommandNotFound = func(_ *cli.Context, command string) {
38-
logrus.Fatalf("Command %s not found.", command)
39-
}
40-
41-
if err := app.Run(os.Args); err != nil {
40+
if err := cmd.Run(context.Background(), os.Args); err != nil {
4241
logrus.Fatal(err)
4342
}
4443
}

pkg/commands/global/global.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package global
22

33
import (
4+
"context"
45
"fmt"
56
"path"
67
"runtime"
78

89
"github.com/sirupsen/logrus"
9-
"github.com/urfave/cli/v2"
10+
"github.com/urfave/cli/v3"
1011
)
1112

1213
func Flags() []cli.Flag {
@@ -15,7 +16,7 @@ func Flags() []cli.Flag {
1516
Name: "log-level",
1617
Usage: "log level",
1718
Aliases: []string{"l"},
18-
EnvVars: []string{"LOGLEVEL"},
19+
Sources: cli.EnvVars("LOGLEVEL"),
1920
Value: "info",
2021
},
2122
&cli.BoolFlag{Name: "log-caller", Usage: "log caller (file:line)"},
@@ -25,7 +26,7 @@ func Flags() []cli.Flag {
2526
}
2627
}
2728

28-
func Before(c *cli.Context) error {
29+
func Before(ctx context.Context, c *cli.Command) (context.Context, error) {
2930
formatter := &logrus.TextFormatter{
3031
DisableColors: c.Bool("log-disable-color"),
3132
FullTimestamp: c.Bool("log-full-timestamp"),
@@ -55,5 +56,5 @@ func Before(c *cli.Context) error {
5556
logrus.SetLevel(logrus.ErrorLevel)
5657
}
5758

58-
return nil
59+
return ctx, nil
5960
}

pkg/commands/list/command.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package list
22

33
import (
4+
"context"
45
"fmt"
56
"sort"
67

7-
"github.com/urfave/cli/v2"
8+
"github.com/urfave/cli/v3"
89

910
"github.com/ekristen/libnuke/pkg/registry"
1011

1112
"github.com/qaiser42/stackit-nuke/pkg/commands/global"
1213
"github.com/qaiser42/stackit-nuke/pkg/common"
1314
)
1415

15-
func execute(_ *cli.Context) error {
16+
func execute(_ context.Context, _ *cli.Command) error {
1617
names := registry.GetNames()
1718
sort.Strings(names)
1819
for _, n := range names {

pkg/commands/run/command.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"time"
88

99
"github.com/sirupsen/logrus"
10-
"github.com/urfave/cli/v2"
10+
"github.com/urfave/cli/v3"
1111

1212
libconfig "github.com/ekristen/libnuke/pkg/config"
1313
"github.com/ekristen/libnuke/pkg/filter"
@@ -22,14 +22,14 @@ import (
2222
"github.com/qaiser42/stackit-nuke/pkg/stackit"
2323
)
2424

25-
func execute(c *cli.Context) error {
26-
ctx, cancel := context.WithCancel(c.Context)
25+
func execute(ctx context.Context, c *cli.Command) error {
26+
ctx, cancel := context.WithCancel(ctx)
2727
defer cancel()
2828

2929
logger := logrus.StandardLogger()
3030

3131
parsedConfig, err := config.New(libconfig.Options{
32-
Path: c.Path("config"),
32+
Path: c.String("config"),
3333
Deprecations: registry.GetDeprecatedResourceTypeMapping(),
3434
})
3535
if err != nil {
@@ -162,18 +162,18 @@ func firstNonEmpty(vals ...string) string {
162162

163163
func init() {
164164
flags := []cli.Flag{
165-
&cli.PathFlag{Name: "config", Usage: "path to config file", Value: "config.yaml"},
165+
&cli.StringFlag{Name: "config", Usage: "path to config file", Value: "config.yaml"},
166166
&cli.StringSliceFlag{Name: "include", Usage: "only include this specific resource"},
167167
&cli.StringSliceFlag{Name: "exclude", Usage: "exclude this specific resource (overrides everything)"},
168168
&cli.BoolFlag{Name: "quiet", Aliases: []string{"q"}, Usage: "hide filtered messages"},
169169
&cli.BoolFlag{Name: "no-dry-run", Usage: "actually delete after discovery (default: dry-run)"},
170170
&cli.BoolFlag{Name: "no-prompt", Aliases: []string{"force"}, Usage: "skip the typed-confirmation prompt"},
171171
&cli.IntFlag{Name: "prompt-delay", Aliases: []string{"force-sleep"}, Usage: "seconds to wait after prompt before running (min 3)", Value: 10},
172172
&cli.StringSliceFlag{Name: "feature-flag", Usage: "enable experimental behavior"},
173-
&cli.StringFlag{Name: "auth-file", Usage: "path to STACKIT service-account key JSON", EnvVars: []string{"STACKIT_SERVICE_ACCOUNT_KEY_PATH"}},
174-
&cli.StringFlag{Name: "private-key-file", Usage: "path to RSA private key (for service-account key auth)", EnvVars: []string{"STACKIT_PRIVATE_KEY_PATH"}},
175-
&cli.StringFlag{Name: "token", Usage: "STACKIT bearer token", EnvVars: []string{"STACKIT_SERVICE_ACCOUNT_TOKEN"}},
176-
&cli.StringSliceFlag{Name: "project-id", Usage: "narrow nuke to one or more project IDs from the config allow-list", EnvVars: []string{"STACKIT_PROJECT_ID"}},
173+
&cli.StringFlag{Name: "auth-file", Usage: "path to STACKIT service-account key JSON", Sources: cli.EnvVars("STACKIT_SERVICE_ACCOUNT_KEY_PATH")},
174+
&cli.StringFlag{Name: "private-key-file", Usage: "path to RSA private key (for service-account key auth)", Sources: cli.EnvVars("STACKIT_PRIVATE_KEY_PATH")},
175+
&cli.StringFlag{Name: "token", Usage: "STACKIT bearer token", Sources: cli.EnvVars("STACKIT_SERVICE_ACCOUNT_TOKEN")},
176+
&cli.StringSliceFlag{Name: "project-id", Usage: "narrow nuke to one or more project IDs from the config allow-list", Sources: cli.EnvVars("STACKIT_PROJECT_ID")},
177177
}
178178

179179
cmd := &cli.Command{

pkg/common/commands.go

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

33
import (
44
"github.com/sirupsen/logrus"
5-
"github.com/urfave/cli/v2"
5+
"github.com/urfave/cli/v3"
66
)
77

88
var commands []*cli.Command

renovate.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
"matchUpdateTypes": ["minor", "patch"],
2727
"groupName": "go modules (non-major)"
2828
},
29+
{
30+
"description": "Go module major upgrades change the import path and usually break the API — they need a manual code migration. Gate behind Dependency Dashboard approval so renovate surfaces them but never auto-opens an uncompilable PR.",
31+
"matchManagers": ["gomod"],
32+
"matchUpdateTypes": ["major"],
33+
"dependencyDashboardApproval": true,
34+
"automerge": false
35+
},
2936
{
3037
"description": "libnuke — manual, own PR so it doesn't block the group's automerge",
3138
"matchPackageNames": ["github.com/ekristen/libnuke"],

0 commit comments

Comments
 (0)