summaryrefslogtreecommitdiffstats
path: root/cmd/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/main.go')
-rw-r--r--cmd/main.go37
1 files changed, 1 insertions, 36 deletions
diff --git a/cmd/main.go b/cmd/main.go
index e44f9382b7..13f9bba013 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -6,8 +6,6 @@ package cmd
import (
"fmt"
"os"
- "reflect"
- "strings"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -58,7 +56,6 @@ func appGlobalFlags() []cli.Flag {
return []cli.Flag{
// make the builtin flags at the top
helpFlag,
- cli.VersionFlag,
// shared configuration flags, they are for global and for each sub-command at the same time
// eg: such command is valid: "./gitea --config /tmp/app.ini web --config /tmp/app.ini", while it's discouraged indeed
@@ -120,36 +117,6 @@ func prepareWorkPathAndCustomConf(action cli.ActionFunc) func(ctx *cli.Context)
}
}
-func reflectGet(v any, fieldName string) any {
- e := reflect.ValueOf(v).Elem()
- return e.FieldByName(fieldName).Interface()
-}
-
-// https://cli.urfave.org/migrate-v1-to-v2/#flag-aliases-are-done-differently
-// Sadly v2 doesn't warn you if a comma is in the name. (https://github.com/urfave/cli/issues/1103)
-func checkCommandFlags(c any) bool {
- var cmds []*cli.Command
- if app, ok := c.(*cli.App); ok {
- cmds = app.Commands
- } else {
- cmds = c.(*cli.Command).Subcommands
- }
- ok := true
- for _, cmd := range cmds {
- for _, flag := range cmd.Flags {
- flagName := reflectGet(flag, "Name").(string)
- if strings.Contains(flagName, ",") {
- ok = false
- log.Error("cli.Flag can't have comma in its Name: %q, use Aliases instead", flagName)
- }
- }
- if !checkCommandFlags(cmd) {
- ok = false
- }
- }
- return ok
-}
-
func NewMainApp() *cli.App {
app := cli.NewApp()
app.EnableBashCompletion = true
@@ -187,6 +154,7 @@ func NewMainApp() *cli.App {
app.DefaultCommand = CmdWeb.Name
globalFlags := appGlobalFlags()
+ app.Flags = append(app.Flags, cli.VersionFlag)
app.Flags = append(app.Flags, globalFlags...)
app.HideHelp = true // use our own help action to show helps (with more information like default config)
app.Before = PrepareConsoleLoggerLevel(log.INFO)
@@ -196,8 +164,5 @@ func NewMainApp() *cli.App {
app.Commands = append(app.Commands, subCmdWithConfig...)
app.Commands = append(app.Commands, subCmdStandalone...)
- if !checkCommandFlags(app) {
- panic("some flags are incorrect") // this is a runtime check to help developers
- }
return app
}