Skip to content

Commit d281b11

Browse files
committed
migrate to urfave v3
1 parent 4011e22 commit d281b11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+326
-294
lines changed

cmd/actions.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
package cmd
55

66
import (
7+
"context"
78
"fmt"
89

910
"code.gitea.io/gitea/modules/private"
1011
"code.gitea.io/gitea/modules/setting"
1112

12-
"github.com/urfave/cli/v2"
13+
"github.com/urfave/cli/v3"
1314
)
1415

1516
var (
1617
// CmdActions represents the available actions sub-commands.
1718
CmdActions = &cli.Command{
1819
Name: "actions",
1920
Usage: "Manage Gitea Actions",
20-
Subcommands: []*cli.Command{
21+
Commands: []*cli.Command{
2122
subcmdActionsGenRunnerToken,
2223
},
2324
}
@@ -38,7 +39,7 @@ var (
3839
}
3940
)
4041

41-
func runGenerateActionsRunnerToken(c *cli.Context) error {
42+
func runGenerateActionsRunnerToken(_ context.Context, c *cli.Command) error {
4243
ctx, cancel := installSignals()
4344
defer cancel()
4445

cmd/admin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import (
1515
"code.gitea.io/gitea/modules/log"
1616
repo_module "code.gitea.io/gitea/modules/repository"
1717

18-
"github.com/urfave/cli/v2"
18+
"github.com/urfave/cli/v3"
1919
)
2020

2121
var (
2222
// CmdAdmin represents the available admin sub-command.
2323
CmdAdmin = &cli.Command{
2424
Name: "admin",
2525
Usage: "Perform common administrative operations",
26-
Subcommands: []*cli.Command{
26+
Commands: []*cli.Command{
2727
subcmdUser,
2828
subcmdRepoSyncReleases,
2929
subcmdRegenerate,
@@ -41,7 +41,7 @@ var (
4141
subcmdRegenerate = &cli.Command{
4242
Name: "regenerate",
4343
Usage: "Regenerate specific files",
44-
Subcommands: []*cli.Command{
44+
Commands: []*cli.Command{
4545
microcmdRegenHooks,
4646
microcmdRegenKeys,
4747
},
@@ -50,7 +50,7 @@ var (
5050
subcmdAuth = &cli.Command{
5151
Name: "auth",
5252
Usage: "Modify external auth providers",
53-
Subcommands: []*cli.Command{
53+
Commands: []*cli.Command{
5454
microcmdAuthAddOauth,
5555
microcmdAuthUpdateOauth,
5656
microcmdAuthAddLdapBindDn,
@@ -93,7 +93,7 @@ var (
9393
}
9494
)
9595

96-
func runRepoSyncReleases(_ *cli.Context) error {
96+
func runRepoSyncReleases(_ context.Context, _ *cli.Command) error {
9797
ctx, cancel := installSignals()
9898
defer cancel()
9999

cmd/admin_auth.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
910
"os"
@@ -13,7 +14,7 @@ import (
1314
"code.gitea.io/gitea/models/db"
1415
auth_service "code.gitea.io/gitea/services/auth"
1516

16-
"github.com/urfave/cli/v2"
17+
"github.com/urfave/cli/v3"
1718
)
1819

1920
var (
@@ -56,7 +57,7 @@ var (
5657
}
5758
)
5859

59-
func runListAuth(c *cli.Context) error {
60+
func runListAuth(_ context.Context, c *cli.Command) error {
6061
ctx, cancel := installSignals()
6162
defer cancel()
6263

@@ -90,7 +91,7 @@ func runListAuth(c *cli.Context) error {
9091
return nil
9192
}
9293

93-
func runDeleteAuth(c *cli.Context) error {
94+
func runDeleteAuth(_ context.Context, c *cli.Command) error {
9495
if !c.IsSet("id") {
9596
return errors.New("--id flag is missing")
9697
}

cmd/admin_auth_ldap.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"code.gitea.io/gitea/modules/util"
1313
"code.gitea.io/gitea/services/auth/source/ldap"
1414

15-
"github.com/urfave/cli/v2"
15+
"github.com/urfave/cli/v3"
1616
)
1717

1818
type (
@@ -167,35 +167,35 @@ var (
167167
microcmdAuthAddLdapBindDn = &cli.Command{
168168
Name: "add-ldap",
169169
Usage: "Add new LDAP (via Bind DN) authentication source",
170-
Action: func(c *cli.Context) error {
171-
return newAuthService().addLdapBindDn(c)
170+
Action: func(ctx context.Context, cmd *cli.Command) error {
171+
return newAuthService().addLdapBindDn(ctx, cmd)
172172
},
173173
Flags: ldapBindDnCLIFlags,
174174
}
175175

176176
microcmdAuthUpdateLdapBindDn = &cli.Command{
177177
Name: "update-ldap",
178178
Usage: "Update existing LDAP (via Bind DN) authentication source",
179-
Action: func(c *cli.Context) error {
180-
return newAuthService().updateLdapBindDn(c)
179+
Action: func(ctx context.Context, cmd *cli.Command) error {
180+
return newAuthService().updateLdapBindDn(ctx, cmd)
181181
},
182182
Flags: append([]cli.Flag{idFlag}, ldapBindDnCLIFlags...),
183183
}
184184

185185
microcmdAuthAddLdapSimpleAuth = &cli.Command{
186186
Name: "add-ldap-simple",
187187
Usage: "Add new LDAP (simple auth) authentication source",
188-
Action: func(c *cli.Context) error {
189-
return newAuthService().addLdapSimpleAuth(c)
188+
Action: func(ctx context.Context, cmd *cli.Command) error {
189+
return newAuthService().addLdapSimpleAuth(ctx, cmd)
190190
},
191191
Flags: ldapSimpleAuthCLIFlags,
192192
}
193193

194194
microcmdAuthUpdateLdapSimpleAuth = &cli.Command{
195195
Name: "update-ldap-simple",
196196
Usage: "Update existing LDAP (simple auth) authentication source",
197-
Action: func(c *cli.Context) error {
198-
return newAuthService().updateLdapSimpleAuth(c)
197+
Action: func(ctx context.Context, cmd *cli.Command) error {
198+
return newAuthService().updateLdapSimpleAuth(ctx, cmd)
199199
},
200200
Flags: append([]cli.Flag{idFlag}, ldapSimpleAuthCLIFlags...),
201201
}
@@ -212,7 +212,7 @@ func newAuthService() *authService {
212212
}
213213

214214
// parseAuthSourceLdap assigns values on authSource according to command line flags.
215-
func parseAuthSourceLdap(c *cli.Context, authSource *auth.Source) {
215+
func parseAuthSourceLdap(c *cli.Command, authSource *auth.Source) {
216216
if c.IsSet("name") {
217217
authSource.Name = c.String("name")
218218
}
@@ -232,7 +232,7 @@ func parseAuthSourceLdap(c *cli.Context, authSource *auth.Source) {
232232
}
233233

234234
// parseLdapConfig assigns values on config according to command line flags.
235-
func parseLdapConfig(c *cli.Context, config *ldap.Source) error {
235+
func parseLdapConfig(c *cli.Command, config *ldap.Source) error {
236236
if c.IsSet("name") {
237237
config.Name = c.String("name")
238238
}
@@ -337,7 +337,7 @@ func findLdapSecurityProtocolByName(name string) (ldap.SecurityProtocol, bool) {
337337

338338
// getAuthSource gets the login source by its id defined in the command line flags.
339339
// It returns an error if the id is not set, does not match any source or if the source is not of expected type.
340-
func (a *authService) getAuthSource(ctx context.Context, c *cli.Context, authType auth.Type) (*auth.Source, error) {
340+
func (a *authService) getAuthSource(ctx context.Context, c *cli.Command, authType auth.Type) (*auth.Source, error) {
341341
if err := argsSet(c, "id"); err != nil {
342342
return nil, err
343343
}
@@ -355,7 +355,7 @@ func (a *authService) getAuthSource(ctx context.Context, c *cli.Context, authTyp
355355
}
356356

357357
// addLdapBindDn adds a new LDAP via Bind DN authentication source.
358-
func (a *authService) addLdapBindDn(c *cli.Context) error {
358+
func (a *authService) addLdapBindDn(_ context.Context, c *cli.Command) error {
359359
if err := argsSet(c, "name", "security-protocol", "host", "port", "user-search-base", "user-filter", "email-attribute"); err != nil {
360360
return err
361361
}
@@ -384,7 +384,7 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
384384
}
385385

386386
// updateLdapBindDn updates a new LDAP via Bind DN authentication source.
387-
func (a *authService) updateLdapBindDn(c *cli.Context) error {
387+
func (a *authService) updateLdapBindDn(_ context.Context, c *cli.Command) error {
388388
ctx, cancel := installSignals()
389389
defer cancel()
390390

@@ -406,7 +406,7 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
406406
}
407407

408408
// addLdapSimpleAuth adds a new LDAP (simple auth) authentication source.
409-
func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
409+
func (a *authService) addLdapSimpleAuth(_ context.Context, c *cli.Command) error {
410410
if err := argsSet(c, "name", "security-protocol", "host", "port", "user-dn", "user-filter", "email-attribute"); err != nil {
411411
return err
412412
}
@@ -435,7 +435,7 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
435435
}
436436

437437
// updateLdapSimpleAuth updates a new LDAP (simple auth) authentication source.
438-
func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
438+
func (a *authService) updateLdapSimpleAuth(_ context.Context, c *cli.Command) error {
439439
ctx, cancel := installSignals()
440440
defer cancel()
441441

cmd/admin_auth_ldap_test.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"code.gitea.io/gitea/services/auth/source/ldap"
1212

1313
"github.com/stretchr/testify/assert"
14-
"github.com/urfave/cli/v2"
14+
"github.com/urfave/cli/v3"
1515
)
1616

1717
func TestAddLdapBindDn(t *testing.T) {
@@ -239,12 +239,13 @@ func TestAddLdapBindDn(t *testing.T) {
239239
}
240240

241241
// Create a copy of command to test
242-
app := cli.NewApp()
243-
app.Flags = microcmdAuthAddLdapBindDn.Flags
244-
app.Action = service.addLdapBindDn
242+
app := cli.Command{
243+
Flags: microcmdAuthAddLdapBindDn.Flags,
244+
Action: service.addLdapBindDn,
245+
}
245246

246247
// Run it
247-
err := app.Run(c.args)
248+
err := app.Run(t.Context(), c.args)
248249
if c.errMsg != "" {
249250
assert.EqualError(t, err, c.errMsg, "case %d: error should match", n)
250251
} else {
@@ -470,12 +471,13 @@ func TestAddLdapSimpleAuth(t *testing.T) {
470471
}
471472

472473
// Create a copy of command to test
473-
app := cli.NewApp()
474-
app.Flags = microcmdAuthAddLdapSimpleAuth.Flags
475-
app.Action = service.addLdapSimpleAuth
474+
app := &cli.Command{
475+
Flags: microcmdAuthAddLdapSimpleAuth.Flags,
476+
Action: service.addLdapSimpleAuth,
477+
}
476478

477479
// Run it
478-
err := app.Run(c.args)
480+
err := app.Run(t.Context(), c.args)
479481
if c.errMsg != "" {
480482
assert.EqualError(t, err, c.errMsg, "case %d: error should match", n)
481483
} else {
@@ -947,12 +949,12 @@ func TestUpdateLdapBindDn(t *testing.T) {
947949
}
948950

949951
// Create a copy of command to test
950-
app := cli.NewApp()
951-
app.Flags = microcmdAuthUpdateLdapBindDn.Flags
952-
app.Action = service.updateLdapBindDn
953-
952+
app := cli.Command{
953+
Flags: microcmdAuthUpdateLdapBindDn.Flags,
954+
Action: service.updateLdapBindDn,
955+
}
954956
// Run it
955-
err := app.Run(c.args)
957+
err := app.Run(t.Context(), c.args)
956958
if c.errMsg != "" {
957959
assert.EqualError(t, err, c.errMsg, "case %d: error should match", n)
958960
} else {
@@ -1337,12 +1339,12 @@ func TestUpdateLdapSimpleAuth(t *testing.T) {
13371339
}
13381340

13391341
// Create a copy of command to test
1340-
app := cli.NewApp()
1341-
app.Flags = microcmdAuthUpdateLdapSimpleAuth.Flags
1342-
app.Action = service.updateLdapSimpleAuth
1343-
1342+
app := cli.Command{
1343+
Flags: microcmdAuthUpdateLdapSimpleAuth.Flags,
1344+
Action: service.updateLdapSimpleAuth,
1345+
}
13441346
// Run it
1345-
err := app.Run(c.args)
1347+
err := app.Run(t.Context(), c.args)
13461348
if c.errMsg != "" {
13471349
assert.EqualError(t, err, c.errMsg, "case %d: error should match", n)
13481350
} else {

cmd/admin_auth_oauth.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
910
"net/url"
@@ -12,7 +13,7 @@ import (
1213
"code.gitea.io/gitea/modules/util"
1314
"code.gitea.io/gitea/services/auth/source/oauth2"
1415

15-
"github.com/urfave/cli/v2"
16+
"github.com/urfave/cli/v3"
1617
)
1718

1819
var (
@@ -137,7 +138,7 @@ var (
137138
}
138139
)
139140

140-
func parseOAuth2Config(c *cli.Context) *oauth2.Source {
141+
func parseOAuth2Config(c *cli.Command) *oauth2.Source {
141142
var customURLMapping *oauth2.CustomURLMapping
142143
if c.IsSet("use-custom-urls") {
143144
customURLMapping = &oauth2.CustomURLMapping{
@@ -168,7 +169,7 @@ func parseOAuth2Config(c *cli.Context) *oauth2.Source {
168169
}
169170
}
170171

171-
func runAddOauth(c *cli.Context) error {
172+
func runAddOauth(_ context.Context, c *cli.Command) error {
172173
ctx, cancel := installSignals()
173174
defer cancel()
174175

@@ -193,7 +194,7 @@ func runAddOauth(c *cli.Context) error {
193194
})
194195
}
195196

196-
func runUpdateOauth(c *cli.Context) error {
197+
func runUpdateOauth(_ context.Context, c *cli.Command) error {
197198
if !c.IsSet("id") {
198199
return errors.New("--id flag is missing")
199200
}

cmd/admin_auth_stmp.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
package cmd
55

66
import (
7+
"context"
78
"errors"
89
"strings"
910

1011
auth_model "code.gitea.io/gitea/models/auth"
1112
"code.gitea.io/gitea/modules/util"
1213
"code.gitea.io/gitea/services/auth/source/smtp"
1314

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

1718
var (
@@ -87,7 +88,7 @@ var (
8788
}
8889
)
8990

90-
func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
91+
func parseSMTPConfig(c *cli.Command, conf *smtp.Source) error {
9192
if c.IsSet("auth-type") {
9293
conf.Auth = c.String("auth-type")
9394
validAuthTypes := []string{"PLAIN", "LOGIN", "CRAM-MD5"}
@@ -120,7 +121,7 @@ func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
120121
return nil
121122
}
122123

123-
func runAddSMTP(c *cli.Context) error {
124+
func runAddSMTP(_ context.Context, c *cli.Command) error {
124125
ctx, cancel := installSignals()
125126
defer cancel()
126127

@@ -161,7 +162,7 @@ func runAddSMTP(c *cli.Context) error {
161162
})
162163
}
163164

164-
func runUpdateSMTP(c *cli.Context) error {
165+
func runUpdateSMTP(_ context.Context, c *cli.Command) error {
165166
if !c.IsSet("id") {
166167
return errors.New("--id flag is missing")
167168
}

0 commit comments

Comments
 (0)