Switch cmd/ to use constructor functions. (#36962)

This is a step towards potentially splitting command groups into their
own folders to clean up `cmd/` as one folder for all cli commands.
Returning fresh command instances will also aid in adding tests as you
don't need to concern yourself with the whole command tree being one
mutable variable.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
techknowlogick
2026-03-25 10:53:13 -04:00
committed by GitHub
parent bb1e22bba4
commit 435123fe65
26 changed files with 651 additions and 578 deletions

View File

@@ -13,17 +13,18 @@ import (
"github.com/urfave/cli/v3"
)
var (
// CmdActions represents the available actions sub-commands.
CmdActions = &cli.Command{
func newActionsCommand() *cli.Command {
return &cli.Command{
Name: "actions",
Usage: "Manage Gitea Actions",
Commands: []*cli.Command{
subcmdActionsGenRunnerToken,
newActionsGenerateRunnerTokenCommand(),
},
}
}
subcmdActionsGenRunnerToken = &cli.Command{
func newActionsGenerateRunnerTokenCommand() *cli.Command {
return &cli.Command{
Name: "generate-runner-token",
Usage: "Generate a new token for a runner to use to register with the server",
Action: runGenerateActionsRunnerToken,
@@ -37,7 +38,7 @@ var (
},
},
}
)
}
func runGenerateActionsRunnerToken(ctx context.Context, c *cli.Command) error {
setting.MustInstalled()

View File

@@ -18,36 +18,41 @@ import (
"github.com/urfave/cli/v3"
)
var (
// CmdAdmin represents the available admin sub-command.
CmdAdmin = &cli.Command{
func newAdminCommand() *cli.Command {
return &cli.Command{
Name: "admin",
Usage: "Perform common administrative operations",
Commands: []*cli.Command{
subcmdUser,
subcmdRepoSyncReleases,
subcmdRegenerate,
subcmdAuth,
subcmdSendMail,
newUserCommand(),
newRepoSyncReleasesCommand(),
newRegenerateCommand(),
newAuthCommand(),
newSendMailCommand(),
},
}
}
subcmdRepoSyncReleases = &cli.Command{
func newRepoSyncReleasesCommand() *cli.Command {
return &cli.Command{
Name: "repo-sync-releases",
Usage: "Synchronize repository releases with tags",
Action: runRepoSyncReleases,
}
}
subcmdRegenerate = &cli.Command{
func newRegenerateCommand() *cli.Command {
return &cli.Command{
Name: "regenerate",
Usage: "Regenerate specific files",
Commands: []*cli.Command{
microcmdRegenHooks,
microcmdRegenKeys,
newRegenerateHooksCommand(),
newRegenerateKeysCommand(),
},
}
}
subcmdAuth = &cli.Command{
func newAuthCommand() *cli.Command {
return &cli.Command{
Name: "auth",
Usage: "Modify external auth providers",
Commands: []*cli.Command{
@@ -59,12 +64,14 @@ var (
microcmdAuthUpdateLdapSimpleAuth(),
microcmdAuthAddSMTP(),
microcmdAuthUpdateSMTP(),
microcmdAuthList,
microcmdAuthDelete,
newAuthListCommand(),
newAuthDeleteCommand(),
},
}
}
subcmdSendMail = &cli.Command{
func newSendMailCommand() *cli.Command {
return &cli.Command{
Name: "sendmail",
Usage: "Send a message to all users",
Action: runSendMail,
@@ -86,7 +93,7 @@ var (
},
},
}
)
}
func idFlag() *cli.Int64Flag {
return &cli.Int64Flag{

View File

@@ -17,14 +17,17 @@ import (
"github.com/urfave/cli/v3"
)
var (
microcmdAuthDelete = &cli.Command{
func newAuthDeleteCommand() *cli.Command {
return &cli.Command{
Name: "delete",
Usage: "Delete specific auth source",
Flags: []cli.Flag{idFlag()},
Action: runDeleteAuth,
}
microcmdAuthList = &cli.Command{
}
func newAuthListCommand() *cli.Command {
return &cli.Command{
Name: "list",
Usage: "List auth sources",
Action: runListAuth,
@@ -55,7 +58,7 @@ var (
},
},
}
)
}
func runListAuth(ctx context.Context, c *cli.Command) error {
if err := initDB(ctx); err != nil {

View File

@@ -13,19 +13,21 @@ import (
"github.com/urfave/cli/v3"
)
var (
microcmdRegenHooks = &cli.Command{
func newRegenerateHooksCommand() *cli.Command {
return &cli.Command{
Name: "hooks",
Usage: "Regenerate git-hooks",
Action: runRegenerateHooks,
}
}
microcmdRegenKeys = &cli.Command{
func newRegenerateKeysCommand() *cli.Command {
return &cli.Command{
Name: "keys",
Usage: "Regenerate authorized_keys file",
Action: runRegenerateKeys,
}
)
}
func runRegenerateHooks(ctx context.Context, _ *cli.Command) error {
if err := initDB(ctx); err != nil {

View File

@@ -7,15 +7,17 @@ import (
"github.com/urfave/cli/v3"
)
var subcmdUser = &cli.Command{
func newUserCommand() *cli.Command {
return &cli.Command{
Name: "user",
Usage: "Modify users",
Commands: []*cli.Command{
microcmdUserCreate(),
microcmdUserList,
newUserListCommand(),
microcmdUserChangePassword(),
microcmdUserDelete(),
microcmdUserGenerateAccessToken,
newUserGenerateAccessTokenCommand(),
microcmdUserMustChangePassword(),
},
}
}

View File

@@ -14,7 +14,8 @@ import (
"github.com/urfave/cli/v3"
)
var microcmdUserGenerateAccessToken = &cli.Command{
func newUserGenerateAccessTokenCommand() *cli.Command {
return &cli.Command{
Name: "generate-access-token",
Usage: "Generate an access token for a specific user",
Flags: []cli.Flag{
@@ -41,6 +42,7 @@ var microcmdUserGenerateAccessToken = &cli.Command{
},
Action: runGenerateAccessToken,
}
}
func runGenerateAccessToken(ctx context.Context, c *cli.Command) error {
if !c.IsSet("username") {

View File

@@ -14,7 +14,8 @@ import (
"github.com/urfave/cli/v3"
)
var microcmdUserList = &cli.Command{
func newUserListCommand() *cli.Command {
return &cli.Command{
Name: "list",
Usage: "List users",
Action: runListUsers,
@@ -25,6 +26,7 @@ var microcmdUserList = &cli.Command{
},
},
}
}
func runListUsers(ctx context.Context, c *cli.Command) error {
if err := initDB(ctx); err != nil {

View File

@@ -13,8 +13,8 @@ import (
"github.com/urfave/cli/v3"
)
// CmdDocs represents the available docs sub-command.
var CmdDocs = &cli.Command{
func newDocsCommand() *cli.Command {
return &cli.Command{
Name: "docs",
Usage: "Output CLI documentation",
Description: "A command to output Gitea's CLI documentation, optionally to a file.",
@@ -31,6 +31,7 @@ var CmdDocs = &cli.Command{
},
},
}
}
func runDocs(_ context.Context, cmd *cli.Command) error {
docs, err := cli_docs.ToMarkdown(cmd.Root())

View File

@@ -24,20 +24,21 @@ import (
"xorm.io/xorm"
)
// CmdDoctor represents the available doctor sub-command.
var CmdDoctor = &cli.Command{
func newDoctorCommand() *cli.Command {
return &cli.Command{
Name: "doctor",
Usage: "Diagnose and optionally fix problems, convert or re-create database tables",
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.",
Commands: []*cli.Command{
cmdDoctorCheck,
cmdRecreateTable,
cmdDoctorConvert,
newDoctorCheckCommand(),
newRecreateTableCommand(),
newDoctorConvertCommand(),
},
}
}
var cmdDoctorCheck = &cli.Command{
func newDoctorCheckCommand() *cli.Command {
return &cli.Command{
Name: "check",
Usage: "Diagnose and optionally fix problems",
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.",
@@ -74,8 +75,10 @@ var cmdDoctorCheck = &cli.Command{
},
},
}
}
var cmdRecreateTable = &cli.Command{
func newRecreateTableCommand() *cli.Command {
return &cli.Command{
Name: "recreate-table",
Usage: "Recreate tables from XORM definitions and copy the data.",
ArgsUsage: "[TABLE]... : (TABLEs to recreate - leave blank for all)",
@@ -92,6 +95,7 @@ This command will cause Xorm to recreate tables, copying over the data and delet
You should back-up your database before doing this and ensure that your database is up-to-date first.`,
Action: runRecreateTable,
}
}
func runRecreateTable(ctx context.Context, cmd *cli.Command) error {
// Redirect the default golog to here

View File

@@ -14,13 +14,14 @@ import (
"github.com/urfave/cli/v3"
)
// cmdDoctorConvert represents the available convert sub-command.
var cmdDoctorConvert = &cli.Command{
func newDoctorConvertCommand() *cli.Command {
return &cli.Command{
Name: "convert",
Usage: "Convert the database",
Description: "A command to convert an existing MySQL database from utf8 to utf8mb4 or MSSQL database from varchar to nvarchar",
Action: runDoctorConvert,
}
}
func runDoctorConvert(ctx context.Context, cmd *cli.Command) error {
if err := initDB(ctx); err != nil {

View File

@@ -23,7 +23,7 @@ func TestDoctorRun(t *testing.T) {
SkipDatabaseInitialization: true,
})
app := &cli.Command{
Commands: []*cli.Command{cmdDoctorCheck},
Commands: []*cli.Command{newDoctorCheckCommand()},
}
err := app.Run(t.Context(), []string{"./gitea", "check", "--run", "test-check"})
assert.NoError(t, err)

View File

@@ -23,8 +23,8 @@ import (
"github.com/urfave/cli/v3"
)
// CmdDump represents the available dump sub-command.
var CmdDump = &cli.Command{
func newDumpCommand() *cli.Command {
return &cli.Command{
Name: "dump",
Usage: "Dump Gitea files and database",
Description: `Dump compresses all related files and database into zip file. It can be used for backup and capture Gitea server image to send to maintainer`,
@@ -96,6 +96,7 @@ var CmdDump = &cli.Command{
},
},
}
}
func fatal(format string, args ...any) {
log.Fatal(format, args...)

View File

@@ -22,8 +22,8 @@ import (
"github.com/urfave/cli/v3"
)
// CmdDumpRepository represents the available dump repository sub-command.
var CmdDumpRepository = &cli.Command{
func newDumpRepositoryCommand() *cli.Command {
return &cli.Command{
Name: "dump-repo",
Usage: "Dump the repository from git/github/gitea/gitlab",
Description: "This is a command for dumping the repository data.",
@@ -78,6 +78,7 @@ wiki, issues, labels, releases, release_assets, milestones, pull_requests, comme
},
},
}
}
func runDumpRepository(ctx context.Context, cmd *cli.Command) error {
setupConsoleLogger(log.INFO, log.CanColorStderr, os.Stderr)

View File

@@ -23,20 +23,23 @@ import (
"github.com/urfave/cli/v3"
)
// CmdEmbedded represents the available extract sub-command.
var (
CmdEmbedded = &cli.Command{
var matchedAssetFiles []assetFile
func newEmbeddedCommand() *cli.Command {
return &cli.Command{
Name: "embedded",
Usage: "Extract embedded resources",
Description: "A command for extracting embedded resources, like templates and images",
Commands: []*cli.Command{
subcmdList,
subcmdView,
subcmdExtract,
newEmbeddedListCommand(),
newEmbeddedViewCommand(),
newEmbeddedExtractCommand(),
},
}
}
subcmdList = &cli.Command{
func newEmbeddedListCommand() *cli.Command {
return &cli.Command{
Name: "list",
Usage: "List files matching the given pattern",
Action: runList,
@@ -48,8 +51,10 @@ var (
},
},
}
}
subcmdView = &cli.Command{
func newEmbeddedViewCommand() *cli.Command {
return &cli.Command{
Name: "view",
Usage: "View a file matching the given pattern",
Action: runView,
@@ -61,8 +66,10 @@ var (
},
},
}
}
subcmdExtract = &cli.Command{
func newEmbeddedExtractCommand() *cli.Command {
return &cli.Command{
Name: "extract",
Usage: "Extract resources",
Action: runExtract,
@@ -91,9 +98,7 @@ var (
},
},
}
matchedAssetFiles []assetFile
)
}
type assetFile struct {
fs *assetfs.LayeredFS

View File

@@ -15,45 +15,52 @@ import (
"github.com/urfave/cli/v3"
)
var (
// CmdGenerate represents the available generate sub-command.
CmdGenerate = &cli.Command{
func newGenerateCommand() *cli.Command {
return &cli.Command{
Name: "generate",
Usage: "Generate Gitea's secrets/keys/tokens",
Commands: []*cli.Command{
subcmdSecret,
newGenerateSecretCommand(),
},
}
}
subcmdSecret = &cli.Command{
func newGenerateSecretCommand() *cli.Command {
return &cli.Command{
Name: "secret",
Usage: "Generate a secret token",
Commands: []*cli.Command{
microcmdGenerateInternalToken,
microcmdGenerateLfsJwtSecret,
microcmdGenerateSecretKey,
newGenerateInternalTokenCommand(),
newGenerateLfsJWTSecretCommand(),
newGenerateSecretKeyCommand(),
},
}
}
microcmdGenerateInternalToken = &cli.Command{
func newGenerateInternalTokenCommand() *cli.Command {
return &cli.Command{
Name: "INTERNAL_TOKEN",
Usage: "Generate a new INTERNAL_TOKEN",
Action: runGenerateInternalToken,
}
}
microcmdGenerateLfsJwtSecret = &cli.Command{
func newGenerateLfsJWTSecretCommand() *cli.Command {
return &cli.Command{
Name: "JWT_SECRET",
Aliases: []string{"LFS_JWT_SECRET"},
Usage: "Generate a new JWT_SECRET",
Action: runGenerateLfsJwtSecret,
}
}
microcmdGenerateSecretKey = &cli.Command{
func newGenerateSecretKeyCommand() *cli.Command {
return &cli.Command{
Name: "SECRET_KEY",
Usage: "Generate a new SECRET_KEY",
Action: runGenerateSecretKey,
}
)
}
func runGenerateInternalToken(_ context.Context, c *cli.Command) error {
internalToken, err := generate.NewInternalToken()

View File

@@ -28,23 +28,24 @@ const (
hookBatchSize = 500
)
var (
// CmdHook represents the available hooks sub-command.
CmdHook = &cli.Command{
func newHookCommand() *cli.Command {
return &cli.Command{
Name: "hook",
Usage: "(internal) Should only be called by Git",
Hidden: true, // internal commands shouldn't be visible
Description: "Delegate commands to corresponding Git hooks",
Before: PrepareConsoleLoggerLevel(log.FATAL),
Commands: []*cli.Command{
subcmdHookPreReceive,
subcmdHookUpdate,
subcmdHookPostReceive,
subcmdHookProcReceive,
newHookPreReceiveCommand(),
newHookUpdateCommand(),
newHookPostReceiveCommand(),
newHookProcReceiveCommand(),
},
}
}
subcmdHookPreReceive = &cli.Command{
func newHookPreReceiveCommand() *cli.Command {
return &cli.Command{
Name: "pre-receive",
Usage: "Delegate pre-receive Git hook",
Description: "This command should only be called by Git",
@@ -55,7 +56,10 @@ var (
},
},
}
subcmdHookUpdate = &cli.Command{
}
func newHookUpdateCommand() *cli.Command {
return &cli.Command{
Name: "update",
Usage: "Delegate update Git hook",
Description: "This command should only be called by Git",
@@ -66,7 +70,10 @@ var (
},
},
}
subcmdHookPostReceive = &cli.Command{
}
func newHookPostReceiveCommand() *cli.Command {
return &cli.Command{
Name: "post-receive",
Usage: "Delegate post-receive Git hook",
Description: "This command should only be called by Git",
@@ -77,8 +84,11 @@ var (
},
},
}
}
// Note: new hook since git 2.29
subcmdHookProcReceive = &cli.Command{
func newHookProcReceiveCommand() *cli.Command {
return &cli.Command{
Name: "proc-receive",
Usage: "Delegate proc-receive Git hook",
Description: "This command should only be called by Git",
@@ -89,7 +99,7 @@ var (
},
},
}
)
}
type delayWriter struct {
internal io.Writer

View File

@@ -15,8 +15,9 @@ import (
"github.com/urfave/cli/v3"
)
// CmdKeys represents the available keys sub-command
var CmdKeys = &cli.Command{
// NewKeysCommand returns the internal SSH key lookup sub-command.
func NewKeysCommand() *cli.Command {
return &cli.Command{
Name: "keys",
Usage: "(internal) Should only be called by SSH server",
Hidden: true, // internal commands shouldn't be visible
@@ -50,6 +51,7 @@ var CmdKeys = &cli.Command{
},
},
}
}
func runKeys(ctx context.Context, c *cli.Command) error {
if !c.IsSet("username") {

View File

@@ -112,35 +112,36 @@ func NewMainApp(appVer AppVersion) *cli.Command {
Usage: "Set custom path (defaults to '{WorkPath}/custom')",
},
}
webCmd := newWebCommand()
// these sub-commands need to use a config file
subCmdWithConfig := []*cli.Command{
CmdWeb,
CmdServ,
CmdHook,
CmdKeys,
CmdDump,
CmdAdmin,
CmdMigrate,
CmdDoctor,
CmdManager,
CmdEmbedded,
CmdMigrateStorage,
CmdDumpRepository,
CmdRestoreRepository,
CmdActions,
webCmd,
newServCommand(),
newHookCommand(),
NewKeysCommand(),
newDumpCommand(),
newAdminCommand(),
newMigrateCommand(),
newDoctorCommand(),
newManagerCommand(),
newEmbeddedCommand(),
newMigrateStorageCommand(),
newDumpRepositoryCommand(),
newRestoreRepositoryCommand(),
newActionsCommand(),
}
// these sub-commands do not need the config file, and they do not depend on any path or environment variable.
subCmdStandalone := []*cli.Command{
cmdConfig(),
cmdCert(),
CmdGenerate,
CmdDocs,
newGenerateCommand(),
newDocsCommand(),
}
// TODO: we should eventually drop the default command,
// but not sure whether it would break Windows users who used to double-click the EXE to run.
app.DefaultCommand = CmdWeb.Name
app.DefaultCommand = webCmd.Name
app.Before = PrepareConsoleLoggerLevel(log.INFO)
for i := range subCmdWithConfig {

View File

@@ -13,22 +13,24 @@ import (
"github.com/urfave/cli/v3"
)
var (
// CmdManager represents the manager command
CmdManager = &cli.Command{
func newManagerCommand() *cli.Command {
return &cli.Command{
Name: "manager",
Usage: "Manage the running gitea process",
Description: "This is a command for managing the running gitea process",
Commands: []*cli.Command{
subcmdShutdown,
subcmdRestart,
subcmdReloadTemplates,
subcmdFlushQueues,
subcmdLogging,
subCmdProcesses,
newShutdownCommand(),
newRestartCommand(),
newReloadTemplatesCommand(),
newFlushQueuesCommand(),
newLoggingCommand(),
newProcessesCommand(),
},
}
subcmdShutdown = &cli.Command{
}
func newShutdownCommand() *cli.Command {
return &cli.Command{
Name: "shutdown",
Usage: "Gracefully shutdown the running process",
Flags: []cli.Flag{
@@ -38,7 +40,10 @@ var (
},
Action: runShutdown,
}
subcmdRestart = &cli.Command{
}
func newRestartCommand() *cli.Command {
return &cli.Command{
Name: "restart",
Usage: "Gracefully restart the running process - (not implemented for windows servers)",
Flags: []cli.Flag{
@@ -48,7 +53,10 @@ var (
},
Action: runRestart,
}
subcmdReloadTemplates = &cli.Command{
}
func newReloadTemplatesCommand() *cli.Command {
return &cli.Command{
Name: "reload-templates",
Usage: "Reload template files in the running process",
Flags: []cli.Flag{
@@ -58,7 +66,10 @@ var (
},
Action: runReloadTemplates,
}
subcmdFlushQueues = &cli.Command{
}
func newFlushQueuesCommand() *cli.Command {
return &cli.Command{
Name: "flush-queues",
Usage: "Flush queues in the running process",
Action: runFlushQueues,
@@ -77,7 +88,10 @@ var (
},
},
}
subCmdProcesses = &cli.Command{
}
func newProcessesCommand() *cli.Command {
return &cli.Command{
Name: "processes",
Usage: "Display running processes within the current process",
Action: runProcesses,
@@ -107,7 +121,7 @@ var (
},
},
}
)
}
func runShutdown(ctx context.Context, c *cli.Command) error {
setup(ctx, c.Bool("debug"))

View File

@@ -15,8 +15,8 @@ import (
"github.com/urfave/cli/v3"
)
var (
defaultLoggingFlags = []cli.Flag{
func defaultLoggingFlags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "logger",
Usage: `Logger name - will default to "default"`,
@@ -57,8 +57,10 @@ var (
Name: "debug",
},
}
}
subcmdLogging = &cli.Command{
func newLoggingCommand() *cli.Command {
return &cli.Command{
Name: "logging",
Usage: "Adjust logging commands",
Commands: []*cli.Command{
@@ -109,7 +111,7 @@ var (
{
Name: "file",
Usage: "Add a file logger",
Flags: append(defaultLoggingFlags, []cli.Flag{
Flags: append(defaultLoggingFlags(), []cli.Flag{
&cli.StringFlag{
Name: "filename",
Aliases: []string{"f"},
@@ -150,7 +152,7 @@ var (
}, {
Name: "conn",
Usage: "Add a net conn logger",
Flags: append(defaultLoggingFlags, []cli.Flag{
Flags: append(defaultLoggingFlags(), []cli.Flag{
&cli.BoolFlag{
Name: "reconnect-on-message",
Aliases: []string{"R"},
@@ -191,7 +193,7 @@ var (
},
},
}
)
}
func runRemoveLogger(ctx context.Context, c *cli.Command) error {
setup(ctx, c.Bool("debug"))

View File

@@ -14,13 +14,14 @@ import (
"github.com/urfave/cli/v3"
)
// CmdMigrate represents the available migrate sub-command.
var CmdMigrate = &cli.Command{
func newMigrateCommand() *cli.Command {
return &cli.Command{
Name: "migrate",
Usage: "Migrate the database",
Description: `This is a command for migrating the database, so that you can run "gitea admin create user" before starting the server.`,
Action: runMigrate,
}
}
func runMigrate(ctx context.Context, c *cli.Command) error {
if err := initDB(ctx); err != nil {

View File

@@ -25,8 +25,8 @@ import (
"github.com/urfave/cli/v3"
)
// CmdMigrateStorage represents the available migrate storage sub-command.
var CmdMigrateStorage = &cli.Command{
func newMigrateStorageCommand() *cli.Command {
return &cli.Command{
Name: "migrate-storage",
Usage: "Migrate the storage",
Description: "Copies stored files from storage configured in app.ini to parameter-configured storage",
@@ -127,6 +127,7 @@ var CmdMigrateStorage = &cli.Command{
},
},
}
}
func migrateAttachments(ctx context.Context, dstStorage storage.ObjectStorage) error {
return db.Iterate(ctx, nil, func(ctx context.Context, attach *repo_model.Attachment) error {

View File

@@ -13,8 +13,8 @@ import (
"github.com/urfave/cli/v3"
)
// CmdRestoreRepository represents the available restore a repository sub-command.
var CmdRestoreRepository = &cli.Command{
func newRestoreRepositoryCommand() *cli.Command {
return &cli.Command{
Name: "restore-repo",
Usage: "Restore the repository from disk",
Description: "This is a command for restoring the repository data.",
@@ -48,6 +48,7 @@ wiki, issues, labels, releases, release_assets, milestones, pull_requests, comme
},
},
}
}
func runRestoreRepository(ctx context.Context, c *cli.Command) error {
setting.MustInstalled()

View File

@@ -35,8 +35,8 @@ import (
"github.com/urfave/cli/v3"
)
// CmdServ represents the available serv sub-command.
var CmdServ = &cli.Command{
func newServCommand() *cli.Command {
return &cli.Command{
Name: "serv",
Usage: "(internal) Should only be called by SSH shell",
Description: "Serv provides access auth for repositories",
@@ -52,6 +52,7 @@ var CmdServ = &cli.Command{
},
},
}
}
func setup(ctx context.Context, debug bool) {
if debug {

View File

@@ -34,8 +34,8 @@ import (
// PIDFile could be set from build tag
var PIDFile = "/run/gitea.pid"
// CmdWeb represents the available web sub-command.
var CmdWeb = &cli.Command{
func newWebCommand() *cli.Command {
return &cli.Command{
Name: "web",
Usage: "Start Gitea web server",
Description: `Gitea web server is the only thing you need to run,
@@ -71,6 +71,7 @@ and it takes care of all the other things for you`,
},
},
}
}
func runHTTPRedirector() {
_, _, finished := process.GetManager().AddTypedContext(graceful.GetManager().HammerContext(), "Web: HTTP Redirector", process.SystemProcessType, true)

View File

@@ -10,7 +10,6 @@ import (
"code.gitea.io/gitea/cmd"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
@@ -38,13 +37,14 @@ func Test_CmdKeys(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// FIXME: this test is not quite right. Each "command run" always re-initializes settings
defer test.MockVariableValue(&cmd.CmdKeys.Before, nil)() // don't re-initialize logger during the test
keysCmd := cmd.NewKeysCommand()
keysCmd.Before = nil // don't re-initialize logger during the test
var stdout, stderr bytes.Buffer
app := &cli.Command{
Writer: &stdout,
ErrWriter: &stderr,
Commands: []*cli.Command{cmd.CmdKeys},
Commands: []*cli.Command{keysCmd},
}
err := app.Run(t.Context(), append([]string{"prog"}, tt.args...))
if tt.wantErr {