Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite9f5105

Browse files
Migrate to urfave v3 (#34510)
migrate cli to urfave v3add more cli tests---------Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent2c341b6 commite9f5105

File tree

51 files changed

+1718
-783
lines changed

Some content is hidden

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

51 files changed

+1718
-783
lines changed

‎assets/go-licenses.json‎

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎cmd/actions.go‎

Lines changed: 4 additions & 6 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,10 +39,7 @@ var (
3839
}
3940
)
4041

41-
funcrunGenerateActionsRunnerToken(c*cli.Context)error {
42-
ctx,cancel:=installSignals()
43-
defercancel()
44-
42+
funcrunGenerateActionsRunnerToken(ctx context.Context,c*cli.Command)error {
4543
setting.MustInstalled()
4644

4745
scope:=c.String("scope")

‎cmd/admin.go‎

Lines changed: 20 additions & 21 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,15 +50,15 @@ var (
5050
subcmdAuth=&cli.Command{
5151
Name:"auth",
5252
Usage:"Modify external auth providers",
53-
Subcommands: []*cli.Command{
54-
microcmdAuthAddOauth,
55-
microcmdAuthUpdateOauth,
56-
microcmdAuthAddLdapBindDn,
57-
microcmdAuthUpdateLdapBindDn,
58-
microcmdAuthAddLdapSimpleAuth,
59-
microcmdAuthUpdateLdapSimpleAuth,
60-
microcmdAuthAddSMTP,
61-
microcmdAuthUpdateSMTP,
53+
Commands: []*cli.Command{
54+
microcmdAuthAddOauth(),
55+
microcmdAuthUpdateOauth(),
56+
microcmdAuthAddLdapBindDn(),
57+
microcmdAuthUpdateLdapBindDn(),
58+
microcmdAuthAddLdapSimpleAuth(),
59+
microcmdAuthUpdateLdapSimpleAuth(),
60+
microcmdAuthAddSMTP(),
61+
microcmdAuthUpdateSMTP(),
6262
microcmdAuthList,
6363
microcmdAuthDelete,
6464
},
@@ -70,9 +70,9 @@ var (
7070
Action:runSendMail,
7171
Flags: []cli.Flag{
7272
&cli.StringFlag{
73-
Name:"title",
74-
Usage:`a title of a message`,
75-
Value:"",
73+
Name:"title",
74+
Usage:"a title of a message",
75+
Required:true,
7676
},
7777
&cli.StringFlag{
7878
Name:"content",
@@ -86,17 +86,16 @@ var (
8686
},
8787
},
8888
}
89+
)
8990

90-
idFlag=&cli.Int64Flag{
91+
funcidFlag()*cli.Int64Flag {
92+
return&cli.Int64Flag{
9193
Name:"id",
9294
Usage:"ID of authentication source",
9395
}
94-
)
95-
96-
funcrunRepoSyncReleases(_*cli.Context)error {
97-
ctx,cancel:=installSignals()
98-
defercancel()
96+
}
9997

98+
funcrunRepoSyncReleases(ctx context.Context,_*cli.Command)error {
10099
iferr:=initDB(ctx);err!=nil {
101100
returnerr
102101
}

‎cmd/admin_auth.go‎

Lines changed: 5 additions & 10 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,14 +14,14 @@ 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 (
2021
microcmdAuthDelete=&cli.Command{
2122
Name:"delete",
2223
Usage:"Delete specific auth source",
23-
Flags: []cli.Flag{idFlag},
24+
Flags: []cli.Flag{idFlag()},
2425
Action:runDeleteAuth,
2526
}
2627
microcmdAuthList=&cli.Command{
@@ -56,10 +57,7 @@ var (
5657
}
5758
)
5859

59-
funcrunListAuth(c*cli.Context)error {
60-
ctx,cancel:=installSignals()
61-
defercancel()
62-
60+
funcrunListAuth(ctx context.Context,c*cli.Command)error {
6361
iferr:=initDB(ctx);err!=nil {
6462
returnerr
6563
}
@@ -90,14 +88,11 @@ func runListAuth(c *cli.Context) error {
9088
returnnil
9189
}
9290

93-
funcrunDeleteAuth(c*cli.Context)error {
91+
funcrunDeleteAuth(ctx context.Context,c*cli.Command)error {
9492
if!c.IsSet("id") {
9593
returnerrors.New("--id flag is missing")
9694
}
9795

98-
ctx,cancel:=installSignals()
99-
defercancel()
100-
10196
iferr:=initDB(ctx);err!=nil {
10297
returnerr
10398
}

‎cmd/admin_auth_ldap.go‎

Lines changed: 43 additions & 45 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 (
@@ -24,8 +24,8 @@ type (
2424
}
2525
)
2626

27-
var (
28-
commonLdapCLIFlags= []cli.Flag{
27+
funccommonLdapCLIFlags() []cli.Flag {
28+
return []cli.Flag{
2929
&cli.StringFlag{
3030
Name:"name",
3131
Usage:"Authentication name.",
@@ -103,8 +103,10 @@ var (
103103
Usage:"The attribute of the user’s LDAP record containing the user’s avatar.",
104104
},
105105
}
106+
}
106107

107-
ldapBindDnCLIFlags=append(commonLdapCLIFlags,
108+
funcldapBindDnCLIFlags() []cli.Flag {
109+
returnappend(commonLdapCLIFlags(),
108110
&cli.StringFlag{
109111
Name:"bind-dn",
110112
Usage:"The DN to bind to the LDAP server with when searching for the user.",
@@ -157,49 +159,59 @@ var (
157159
Name:"group-team-map-removal",
158160
Usage:"Remove users from synchronized teams if user does not belong to corresponding LDAP group",
159161
})
162+
}
160163

161-
ldapSimpleAuthCLIFlags=append(commonLdapCLIFlags,
164+
funcldapSimpleAuthCLIFlags() []cli.Flag {
165+
returnappend(commonLdapCLIFlags(),
162166
&cli.StringFlag{
163167
Name:"user-dn",
164168
Usage:"The user's DN.",
165169
})
170+
}
166171

167-
microcmdAuthAddLdapBindDn=&cli.Command{
172+
funcmicrocmdAuthAddLdapBindDn()*cli.Command {
173+
return&cli.Command{
168174
Name:"add-ldap",
169175
Usage:"Add new LDAP (via Bind DN) authentication source",
170-
Action:func(c*cli.Context)error {
171-
returnnewAuthService().addLdapBindDn(c)
176+
Action:func(ctx context.Context,cmd*cli.Command)error {
177+
returnnewAuthService().addLdapBindDn(ctx,cmd)
172178
},
173-
Flags:ldapBindDnCLIFlags,
179+
Flags:ldapBindDnCLIFlags(),
174180
}
181+
}
175182

176-
microcmdAuthUpdateLdapBindDn=&cli.Command{
183+
funcmicrocmdAuthUpdateLdapBindDn()*cli.Command {
184+
return&cli.Command{
177185
Name:"update-ldap",
178186
Usage:"Update existing LDAP (via Bind DN) authentication source",
179-
Action:func(c*cli.Context)error {
180-
returnnewAuthService().updateLdapBindDn(c)
187+
Action:func(ctx context.Context,cmd*cli.Command)error {
188+
returnnewAuthService().updateLdapBindDn(ctx,cmd)
181189
},
182-
Flags:append([]cli.Flag{idFlag},ldapBindDnCLIFlags...),
190+
Flags:append([]cli.Flag{idFlag()},ldapBindDnCLIFlags()...),
183191
}
192+
}
184193

185-
microcmdAuthAddLdapSimpleAuth=&cli.Command{
194+
funcmicrocmdAuthAddLdapSimpleAuth()*cli.Command {
195+
return&cli.Command{
186196
Name:"add-ldap-simple",
187197
Usage:"Add new LDAP (simple auth) authentication source",
188-
Action:func(c*cli.Context)error {
189-
returnnewAuthService().addLdapSimpleAuth(c)
198+
Action:func(ctx context.Context,cmd*cli.Command)error {
199+
returnnewAuthService().addLdapSimpleAuth(ctx,cmd)
190200
},
191-
Flags:ldapSimpleAuthCLIFlags,
201+
Flags:ldapSimpleAuthCLIFlags(),
192202
}
203+
}
193204

194-
microcmdAuthUpdateLdapSimpleAuth=&cli.Command{
205+
funcmicrocmdAuthUpdateLdapSimpleAuth()*cli.Command {
206+
return&cli.Command{
195207
Name:"update-ldap-simple",
196208
Usage:"Update existing LDAP (simple auth) authentication source",
197-
Action:func(c*cli.Context)error {
198-
returnnewAuthService().updateLdapSimpleAuth(c)
209+
Action:func(ctx context.Context,cmd*cli.Command)error {
210+
returnnewAuthService().updateLdapSimpleAuth(ctx,cmd)
199211
},
200-
Flags:append([]cli.Flag{idFlag},ldapSimpleAuthCLIFlags...),
212+
Flags:append([]cli.Flag{idFlag()},ldapSimpleAuthCLIFlags()...),
201213
}
202-
)
214+
}
203215

204216
// newAuthService creates a service with default functions.
205217
funcnewAuthService()*authService {
@@ -212,7 +224,7 @@ func newAuthService() *authService {
212224
}
213225

214226
// parseAuthSourceLdap assigns values on authSource according to command line flags.
215-
funcparseAuthSourceLdap(c*cli.Context,authSource*auth.Source) {
227+
funcparseAuthSourceLdap(c*cli.Command,authSource*auth.Source) {
216228
ifc.IsSet("name") {
217229
authSource.Name=c.String("name")
218230
}
@@ -232,7 +244,7 @@ func parseAuthSourceLdap(c *cli.Context, authSource *auth.Source) {
232244
}
233245

234246
// parseLdapConfig assigns values on config according to command line flags.
235-
funcparseLdapConfig(c*cli.Context,config*ldap.Source)error {
247+
funcparseLdapConfig(c*cli.Command,config*ldap.Source)error {
236248
ifc.IsSet("name") {
237249
config.Name=c.String("name")
238250
}
@@ -245,7 +257,7 @@ func parseLdapConfig(c *cli.Context, config *ldap.Source) error {
245257
ifc.IsSet("security-protocol") {
246258
p,ok:=findLdapSecurityProtocolByName(c.String("security-protocol"))
247259
if!ok {
248-
returnfmt.Errorf("Unknown security protocol name: %s",c.String("security-protocol"))
260+
returnfmt.Errorf("unknown security protocol name: %s",c.String("security-protocol"))
249261
}
250262
config.SecurityProtocol=p
251263
}
@@ -337,32 +349,27 @@ func findLdapSecurityProtocolByName(name string) (ldap.SecurityProtocol, bool) {
337349

338350
// getAuthSource gets the login source by its id defined in the command line flags.
339351
// 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) {
352+
func (a*authService)getAuthSource(ctx context.Context,c*cli.Command,authType auth.Type) (*auth.Source,error) {
341353
iferr:=argsSet(c,"id");err!=nil {
342354
returnnil,err
343355
}
344-
345356
authSource,err:=a.getAuthSourceByID(ctx,c.Int64("id"))
346357
iferr!=nil {
347358
returnnil,err
348359
}
349360

350361
ifauthSource.Type!=authType {
351-
returnnil,fmt.Errorf("Invalid authentication type. expected: %s, actual: %s",authType.String(),authSource.Type.String())
362+
returnnil,fmt.Errorf("invalid authentication type. expected: %s, actual: %s",authType.String(),authSource.Type.String())
352363
}
353364

354365
returnauthSource,nil
355366
}
356367

357368
// addLdapBindDn adds a new LDAP via Bind DN authentication source.
358-
func (a*authService)addLdapBindDn(c*cli.Context)error {
369+
func (a*authService)addLdapBindDn(ctx context.Context,c*cli.Command)error {
359370
iferr:=argsSet(c,"name","security-protocol","host","port","user-search-base","user-filter","email-attribute");err!=nil {
360371
returnerr
361372
}
362-
363-
ctx,cancel:=installSignals()
364-
defercancel()
365-
366373
iferr:=a.initDB(ctx);err!=nil {
367374
returnerr
368375
}
@@ -384,10 +391,7 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
384391
}
385392

386393
// updateLdapBindDn updates a new LDAP via Bind DN authentication source.
387-
func (a*authService)updateLdapBindDn(c*cli.Context)error {
388-
ctx,cancel:=installSignals()
389-
defercancel()
390-
394+
func (a*authService)updateLdapBindDn(ctx context.Context,c*cli.Command)error {
391395
iferr:=a.initDB(ctx);err!=nil {
392396
returnerr
393397
}
@@ -406,14 +410,11 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
406410
}
407411

408412
// addLdapSimpleAuth adds a new LDAP (simple auth) authentication source.
409-
func (a*authService)addLdapSimpleAuth(c*cli.Context)error {
413+
func (a*authService)addLdapSimpleAuth(ctx context.Context,c*cli.Command)error {
410414
iferr:=argsSet(c,"name","security-protocol","host","port","user-dn","user-filter","email-attribute");err!=nil {
411415
returnerr
412416
}
413417

414-
ctx,cancel:=installSignals()
415-
defercancel()
416-
417418
iferr:=a.initDB(ctx);err!=nil {
418419
returnerr
419420
}
@@ -435,10 +436,7 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
435436
}
436437

437438
// updateLdapSimpleAuth updates a new LDAP (simple auth) authentication source.
438-
func (a*authService)updateLdapSimpleAuth(c*cli.Context)error {
439-
ctx,cancel:=installSignals()
440-
defercancel()
441-
439+
func (a*authService)updateLdapSimpleAuth(ctx context.Context,c*cli.Command)error {
442440
iferr:=a.initDB(ctx);err!=nil {
443441
returnerr
444442
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp