loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix CLI sub-command handling (#25501)

A regression of #25330 : The nil "Action" should be treated as "help"

In old releases: `./gitea admin` show helps

After #25330: `./gitea admin` panics (although the code returned `nil`
if action is nil, but Golang's quirk is: nil in interface is not nil)

With this PR: `./gitea admin` shows helps as the old releases.

authored by

wxiaoguang and committed by
GitHub
e409e14b 50dc2d5f

+7 -8
+7 -8
main.go
··· 47 47 // ./gitea -h 48 48 // ./gitea web help 49 49 // ./gitea web -h (due to cli lib limitation, this won't call our cmdHelp, so no extra info) 50 - // ./gitea admin help auth 50 + // ./gitea admin 51 + // ./gitea admin help 52 + // ./gitea admin auth help 51 53 // ./gitea -c /tmp/app.ini -h 52 54 // ./gitea -c /tmp/app.ini help 53 55 // ./gitea help -c /tmp/app.ini ··· 156 158 157 159 // prepareWorkPathAndCustomConf wraps the Action to prepare the work path and custom config 158 160 // It can't use "Before", because each level's sub-command's Before will be called one by one, so the "init" would be done multiple times 159 - func prepareWorkPathAndCustomConf(a any) func(ctx *cli.Context) error { 160 - if a == nil { 161 - return nil 162 - } 163 - action := a.(func(*cli.Context) error) 161 + func prepareWorkPathAndCustomConf(action any) func(ctx *cli.Context) error { 164 162 return func(ctx *cli.Context) error { 165 163 var args setting.ArgWorkPathAndCustomConf 166 164 curCtx := ctx ··· 177 175 curCtx = curCtx.Parent() 178 176 } 179 177 setting.InitWorkPathAndCommonConfig(os.Getenv, args) 180 - if ctx.Bool("help") { 178 + if ctx.Bool("help") || action == nil { 179 + // the default behavior of "urfave/cli": "nil action" means "show help" 181 180 return cmdHelp.Action.(func(ctx *cli.Context) error)(ctx) 182 181 } 183 - return action(ctx) 182 + return action.(func(*cli.Context) error)(ctx) 184 183 } 185 184 } 186 185