summaryrefslogtreecommitdiffstats
path: root/cmd/main.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-07-25 16:38:27 +0200
committerGitHub <noreply@github.com>2023-07-25 16:38:27 +0200
commit1ce51a55e348a2e2fed623790e933408ec59d662 (patch)
tree550e0221ae65fa24531479ee5dc59dc68c39b35b /cmd/main.go
parentFix wrong commit status in web ui (#26121) (diff)
downloadforgejo-1ce51a55e348a2e2fed623790e933408ec59d662.tar.xz
forgejo-1ce51a55e348a2e2fed623790e933408ec59d662.zip
Improve "gitea doctor" sub-command and fix "help" commands (#26072)
Replace #21790 And close #25965 by the way (it needs a separate fix for 1.20) Major changes: 1. Move "gitea convert" to "gitea doctor conver". The old "gitea doctor" still works as a hidden sub-command (to avoid breaking) 2. Do not write "doctor.log" by default, it's not useful in most cases and causes bugs like 25965 3. Improve documents 4. Fix the "help" commands. Before, the "./gitea doctor" can't show the sub-command help correctly (regression of the last cli/v2 refactoring) After this PR: ``` ./gitea help # show all sub-commands for the app ./gitea doctor # show the sub-commands for the "doctor" ./gitea doctor help # show the sub-commands for the "doctor", as above ```
Diffstat (limited to 'cmd/main.go')
-rw-r--r--cmd/main.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/cmd/main.go b/cmd/main.go
index b4a38a4523..e44f9382b7 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
"github.com/urfave/cli/v2"
)
@@ -23,9 +24,13 @@ func cmdHelp() *cli.Command {
Usage: "Shows a list of commands or help for one command",
ArgsUsage: "[command]",
Action: func(c *cli.Context) (err error) {
- args := c.Args()
- if args.Present() {
- err = cli.ShowCommandHelp(c, args.First())
+ lineage := c.Lineage() // The order is from child to parent: help, doctor, Gitea, {Command:nil}
+ targetCmdIdx := 0
+ if c.Command.Name == "help" {
+ targetCmdIdx = 1
+ }
+ if lineage[targetCmdIdx+1].Command != nil {
+ err = cli.ShowCommandHelp(lineage[targetCmdIdx+1], lineage[targetCmdIdx].Command.Name)
} else {
err = cli.ShowAppHelp(c)
}
@@ -94,9 +99,8 @@ func prepareSubcommandWithConfig(command *cli.Command, globalFlags []cli.Flag) {
func prepareWorkPathAndCustomConf(action cli.ActionFunc) func(ctx *cli.Context) error {
return func(ctx *cli.Context) error {
var args setting.ArgWorkPathAndCustomConf
- ctxLineage := ctx.Lineage()
- for i := len(ctxLineage) - 1; i >= 0; i-- {
- curCtx := ctxLineage[i]
+ // from children to parent, check the global flags
+ for _, curCtx := range ctx.Lineage() {
if curCtx.IsSet("work-path") && args.WorkPath == "" {
args.WorkPath = curCtx.String("work-path")
}
@@ -159,7 +163,6 @@ func NewMainApp() *cli.App {
CmdAdmin,
CmdMigrate,
CmdKeys,
- CmdConvert,
CmdDoctor,
CmdManager,
CmdEmbedded,
@@ -170,6 +173,10 @@ func NewMainApp() *cli.App {
cmdHelp(), // the "help" sub-command was used to show the more information for "work path" and "custom config"
}
+ cmdConvert := util.ToPointer(*cmdDoctorConvert)
+ cmdConvert.Hidden = true // still support the legacy "./gitea doctor" by the hidden sub-command, remove it in next release
+ subCmdWithConfig = append(subCmdWithConfig, cmdConvert)
+
// these sub-commands do not need the config file, and they do not depend on any path or environment variable.
subCmdStandalone := []*cli.Command{
CmdCert,