Skip to content

Commit a1cb54e

Browse files
committed
fix
1 parent a12a5f3 commit a1cb54e

File tree

5 files changed

+50
-54
lines changed

5 files changed

+50
-54
lines changed

cmd/doctor.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ import (
2222
"xorm.io/xorm"
2323
)
2424

25-
// CmdDoctor represents the available doctor sub-command.
26-
var CmdDoctor = &cli.Command{
27-
Name: "doctor",
25+
var cmdDoctorCheck = &cli.Command{
26+
Name: "check",
2827
Usage: "Diagnose and optionally fix problems",
2928
Description: "A command to diagnose problems with the current Gitea instance according to the given configuration. Some problems can optionally be fixed by modifying the database or data storage.",
30-
Action: runDoctor,
29+
Action: runDoctorCheck,
3130
Flags: []cli.Flag{
3231
&cli.BoolFlag{
3332
Name: "list",
@@ -51,16 +50,26 @@ var CmdDoctor = &cli.Command{
5150
},
5251
&cli.StringFlag{
5352
Name: "log-file",
54-
Usage: `Name of the log file (default: "doctor.log"). Set to "-" to output to stdout, set to "" to disable`,
53+
Usage: `Name of the log file (no verbose log output by default). Set to "-" to output to stdout`,
5554
},
5655
&cli.BoolFlag{
5756
Name: "color",
5857
Aliases: []string{"H"},
5958
Usage: "Use color for outputted information",
6059
},
6160
},
61+
}
62+
63+
// CmdDoctor represents the available doctor sub-command.
64+
var CmdDoctor = &cli.Command{
65+
Name: "doctor",
66+
Usage: "Diagnose and optionally fix problems",
67+
Description: "A command to diagnose problems with the current Gitea instance according to the given configuration. Some problems can optionally be fixed by modifying the database or data storage.",
68+
6269
Subcommands: []*cli.Command{
70+
cmdDoctorCheck,
6371
cmdRecreateTable,
72+
cmdDoctorConvert,
6473
},
6574
}
6675

@@ -133,16 +142,9 @@ func setupDoctorDefaultLogger(ctx *cli.Context, colorize bool) {
133142
setupConsoleLogger(log.FATAL, log.CanColorStderr, os.Stderr)
134143

135144
logFile := ctx.String("log-file")
136-
if !ctx.IsSet("log-file") {
137-
logFile = "doctor.log"
138-
}
139-
140-
if len(logFile) == 0 {
141-
// if no doctor log-file is set, do not show any log from default logger
142-
return
143-
}
144-
145-
if logFile == "-" {
145+
if logFile == "" {
146+
return // if no doctor log-file is set, do not show any log from default logger
147+
} else if logFile == "-" {
146148
setupConsoleLogger(log.TRACE, colorize, os.Stdout)
147149
} else {
148150
logFile, _ = filepath.Abs(logFile)
@@ -156,7 +158,7 @@ func setupDoctorDefaultLogger(ctx *cli.Context, colorize bool) {
156158
}
157159
}
158160

159-
func runDoctor(ctx *cli.Context) error {
161+
func runDoctorCheck(ctx *cli.Context) error {
160162
stdCtx, cancel := installSignals()
161163
defer cancel()
162164

cmd/convert.go renamed to cmd/doctor_convert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313
"github.com/urfave/cli/v2"
1414
)
1515

16-
// CmdConvert represents the available convert sub-command.
17-
var CmdConvert = &cli.Command{
16+
// cmdDoctorConvert represents the available convert sub-command.
17+
var cmdDoctorConvert = &cli.Command{
1818
Name: "convert",
1919
Usage: "Convert the database",
2020
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
21-
Action: runConvert,
21+
Action: runDoctorConvert,
2222
}
2323

24-
func runConvert(ctx *cli.Context) error {
24+
func runDoctorConvert(ctx *cli.Context) error {
2525
stdCtx, cancel := installSignals()
2626
defer cancel()
2727

cmd/main.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/modules/log"
1313
"code.gitea.io/gitea/modules/setting"
14+
"code.gitea.io/gitea/modules/util"
1415

1516
"github.com/urfave/cli/v2"
1617
)
@@ -23,9 +24,13 @@ func cmdHelp() *cli.Command {
2324
Usage: "Shows a list of commands or help for one command",
2425
ArgsUsage: "[command]",
2526
Action: func(c *cli.Context) (err error) {
26-
args := c.Args()
27-
if args.Present() {
28-
err = cli.ShowCommandHelp(c, args.First())
27+
lineage := c.Lineage() // The order is from child to parent: help, doctor, Gitea, {Command:nil}
28+
targetCmdIdx := 0
29+
if c.Command.Name == "help" {
30+
targetCmdIdx = 1
31+
}
32+
if lineage[targetCmdIdx+1].Command != nil {
33+
err = cli.ShowCommandHelp(lineage[targetCmdIdx+1], lineage[targetCmdIdx].Command.Name)
2934
} else {
3035
err = cli.ShowAppHelp(c)
3136
}
@@ -94,9 +99,8 @@ func prepareSubcommandWithConfig(command *cli.Command, globalFlags []cli.Flag) {
9499
func prepareWorkPathAndCustomConf(action cli.ActionFunc) func(ctx *cli.Context) error {
95100
return func(ctx *cli.Context) error {
96101
var args setting.ArgWorkPathAndCustomConf
97-
ctxLineage := ctx.Lineage()
98-
for i := len(ctxLineage) - 1; i >= 0; i-- {
99-
curCtx := ctxLineage[i]
102+
// from children to parent, check the global flags
103+
for _, curCtx := range ctx.Lineage() {
100104
if curCtx.IsSet("work-path") && args.WorkPath == "" {
101105
args.WorkPath = curCtx.String("work-path")
102106
}
@@ -159,7 +163,6 @@ func NewMainApp() *cli.App {
159163
CmdAdmin,
160164
CmdMigrate,
161165
CmdKeys,
162-
CmdConvert,
163166
CmdDoctor,
164167
CmdManager,
165168
CmdEmbedded,
@@ -170,6 +173,10 @@ func NewMainApp() *cli.App {
170173
cmdHelp(), // the "help" sub-command was used to show the more information for "work path" and "custom config"
171174
}
172175

176+
cmdConvert := util.ToPointer(*cmdDoctorConvert)
177+
cmdConvert.Hidden = true // still support the legacy "./gitea doctor" by the hidden sub-command, remove it in next release
178+
subCmdWithConfig = append(subCmdWithConfig, cmdConvert)
179+
173180
// these sub-commands do not need the config file, and they do not depend on any path or environment variable.
174181
subCmdStandalone := []*cli.Command{
175182
CmdCert,

docs/content/doc/administration/command-line.en-us.md

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -388,35 +388,18 @@ NB: Gitea must be running for this command to succeed.
388388
Migrates the database. This command can be used to run other commands before starting the server for the first time.
389389
This command is idempotent.
390390

391-
### convert
391+
### doctor check
392392

393-
Converts an existing MySQL database from utf8 to utf8mb4.
393+
Diagnose and potentially fix problems with the current Gitea instance.
394+
Several checks are run by default, but additional ones can be run:
394395

395-
### doctor
396+
- `gitea doctor check --list` - will list all the available checks
397+
- `gitea doctor check --all` - will run all available checks
398+
- `gitea doctor check --default` - will run the default checks
399+
- `gitea doctor check --run [check(s),]...` - will run the named checks
396400

397-
Diagnose the problems of current Gitea instance according the given configuration.
398-
Currently there are a check list below:
399-
400-
- Check if OpenSSH authorized_keys file id correct
401-
When your Gitea instance support OpenSSH, your Gitea instance binary path will be written to `authorized_keys`
402-
when there is any public key added or changed on your Gitea instance.
403-
Sometimes if you moved or renamed your Gitea binary when upgrade and you haven't run `Update the '.ssh/authorized_keys' file with Gitea SSH keys. (Not needed for the built-in SSH server.)` on your Admin Panel. Then all pull/push via SSH will not be work.
404-
This check will help you to check if it works well.
405-
406-
For contributors, if you want to add more checks, you can write a new function like `func(ctx *cli.Context) ([]string, error)` and
407-
append it to `doctor.go`.
408-
409-
```go
410-
var checklist = []check{
411-
{
412-
title: "Check if OpenSSH authorized_keys file id correct",
413-
f: runDoctorLocationMoved,
414-
},
415-
// more checks please append here
416-
}
417-
```
418-
419-
This function will receive a command line context and return a list of details about the problems or error.
401+
Some problems can be automatically fixed by passing the `--fix` option.
402+
Extra logging can be set with `--log-file=...`.
420403

421404
#### doctor recreate-table
422405

@@ -448,6 +431,10 @@ gitea doctor recreate-table
448431

449432
It is highly recommended to back-up your database before running these commands.
450433

434+
### doctor convert
435+
436+
Converts a MySQL database from utf8 to utf8mb4 or a MSSQL database from varchar to nvarchar.
437+
451438
### manager
452439

453440
Manage running server operations:

docs/content/doc/usage/secrets.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ menu:
1818
# Secrets
1919

2020
Secrets allow you to store sensitive information in your user, organization or repository.
21-
Secrets are available on Gitea 1.19+ and are only visible in 1.20+ when ACTIONS are enabled
21+
Secrets are available on Gitea 1.19+ and are only visible in 1.20+ when ACTIONS are enabled.
2222

2323
# Naming your secrets
2424

0 commit comments

Comments
 (0)