mirror of
https://codeberg.org/forgejo/forgejo
synced 2025-10-18 22:50:36 +02:00
Fixes #9433. ``` $ ./gitea admin user create --username blah --must-change-password false Hint: boolean false must be specified as a single arg, eg. '--restricted=false', not '--restricted false' Command error: unexpected arguments: false ``` **Breaking**: CLI sub-commands that only have flags would previously ignore anything that might be considered an "extra" argument, and would proceed without any errors. I've manually tested this change on the single `admin user create` command with positive (ensuring cmd still works) and negative (ensuring errors are reported) test cases. I've attempted to ensure the change is applied only to commands which don't use the CLI `Args()` and avoided touching them, including: - `admin user must-change-password` takes a list of users - `doctor recreate-tables` takes a list of tables - `embedded [list/view/extract]` use a pattern of resources to operate upon - git repo hook subcommands, and the ssh serv command, use arguments and have been omitted from the change ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [ ] I want the title to show in the release notes with a link to this pull request. - [x] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9458 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
175 lines
3.9 KiB
Go
175 lines
3.9 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"time"
|
|
|
|
"forgejo.org/modules/private"
|
|
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdManager represents the manager command
|
|
func cmdManager() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "manager",
|
|
Usage: "Manage the running forgejo process",
|
|
Description: "This is a command for managing the running forgejo process",
|
|
Commands: []*cli.Command{
|
|
subcmdShutdown(),
|
|
subcmdRestart(),
|
|
subcmdReloadTemplates(),
|
|
subcmdFlushQueues(),
|
|
subcmdLogging(),
|
|
subCmdProcesses(),
|
|
},
|
|
}
|
|
}
|
|
|
|
func subcmdShutdown() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "shutdown",
|
|
Usage: "Gracefully shutdown the running process",
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
},
|
|
Before: noDanglingArgs,
|
|
Action: runShutdown,
|
|
}
|
|
}
|
|
|
|
func subcmdRestart() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "restart",
|
|
Usage: "Gracefully restart the running process - (not implemented for windows servers)",
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
},
|
|
Before: noDanglingArgs,
|
|
Action: runRestart,
|
|
}
|
|
}
|
|
|
|
func subcmdReloadTemplates() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "reload-templates",
|
|
Usage: "Reload template files in the running process",
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
},
|
|
Before: noDanglingArgs,
|
|
Action: runReloadTemplates,
|
|
}
|
|
}
|
|
|
|
func subcmdFlushQueues() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "flush-queues",
|
|
Usage: "Flush queues in the running process",
|
|
Before: noDanglingArgs,
|
|
Action: runFlushQueues,
|
|
Flags: []cli.Flag{
|
|
&cli.DurationFlag{
|
|
Name: "timeout",
|
|
Value: 60 * time.Second,
|
|
Usage: "Timeout for the flushing process",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "non-blocking",
|
|
Usage: "Set to true to not wait for flush to complete before returning",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func subCmdProcesses() *cli.Command {
|
|
return &cli.Command{
|
|
Name: "processes",
|
|
Usage: "Display running processes within the current process",
|
|
Before: noDanglingArgs,
|
|
Action: runProcesses,
|
|
Flags: []cli.Flag{
|
|
&cli.BoolFlag{
|
|
Name: "debug",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "flat",
|
|
Usage: "Show processes as flat table rather than as tree",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "no-system",
|
|
Usage: "Do not show system processes",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "stacktraces",
|
|
Usage: "Show stacktraces",
|
|
},
|
|
&cli.BoolFlag{
|
|
Name: "json",
|
|
Usage: "Output as json",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "cancel",
|
|
Usage: "Process PID to cancel. (Only available for non-system processes.)",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func runShutdown(ctx context.Context, c *cli.Command) error {
|
|
ctx, cancel := installSignals(ctx)
|
|
defer cancel()
|
|
|
|
setup(ctx, c.Bool("debug"), false)
|
|
extra := private.Shutdown(ctx)
|
|
return handleCliResponseExtra(extra)
|
|
}
|
|
|
|
func runRestart(ctx context.Context, c *cli.Command) error {
|
|
ctx, cancel := installSignals(ctx)
|
|
defer cancel()
|
|
|
|
setup(ctx, c.Bool("debug"), false)
|
|
extra := private.Restart(ctx)
|
|
return handleCliResponseExtra(extra)
|
|
}
|
|
|
|
func runReloadTemplates(ctx context.Context, c *cli.Command) error {
|
|
ctx, cancel := installSignals(ctx)
|
|
defer cancel()
|
|
|
|
setup(ctx, c.Bool("debug"), false)
|
|
extra := private.ReloadTemplates(ctx)
|
|
return handleCliResponseExtra(extra)
|
|
}
|
|
|
|
func runFlushQueues(ctx context.Context, c *cli.Command) error {
|
|
ctx, cancel := installSignals(ctx)
|
|
defer cancel()
|
|
|
|
setup(ctx, c.Bool("debug"), false)
|
|
extra := private.FlushQueues(ctx, c.Duration("timeout"), c.Bool("non-blocking"))
|
|
return handleCliResponseExtra(extra)
|
|
}
|
|
|
|
func runProcesses(ctx context.Context, c *cli.Command) error {
|
|
ctx, cancel := installSignals(ctx)
|
|
defer cancel()
|
|
|
|
setup(ctx, c.Bool("debug"), false)
|
|
extra := private.Processes(ctx, os.Stdout, c.Bool("flat"), c.Bool("no-system"), c.Bool("stacktraces"), c.Bool("json"), c.String("cancel"))
|
|
return handleCliResponseExtra(extra)
|
|
}
|