@@ -47,7 +47,9 @@ func init() {
4747// ./gitea -h
4848// ./gitea web help
4949// ./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
5153// ./gitea -c /tmp/app.ini -h
5254// ./gitea -c /tmp/app.ini help
5355// ./gitea help -c /tmp/app.ini
@@ -156,11 +158,7 @@ func prepareSubcommands(command *cli.Command, defaultFlags []cli.Flag) {
156158
157159// prepareWorkPathAndCustomConf wraps the Action to prepare the work path and custom config
158160// 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 {
164162 return func (ctx * cli.Context ) error {
165163 var args setting.ArgWorkPathAndCustomConf
166164 curCtx := ctx
@@ -177,10 +175,11 @@ func prepareWorkPathAndCustomConf(a any) func(ctx *cli.Context) error {
177175 curCtx = curCtx .Parent ()
178176 }
179177 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"
181180 return cmdHelp .Action .(func (ctx * cli.Context ) error )(ctx )
182181 }
183- return action (ctx )
182+ return action .( func ( * cli. Context ) error ) (ctx )
184183 }
185184}
186185
0 commit comments