diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-08-05 23:36:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-05 23:36:45 +0800 |
commit | d92b4cd0935fcb7be3fb30253426988aada78d32 (patch) | |
tree | cf09184e89a46fc4ee8b1b8901da5f4712dba162 /cmd/main.go | |
parent | 4f513474dce9788bead4799fefe2ed2fdfa75213 (diff) | |
download | gitea-d92b4cd0935fcb7be3fb30253426988aada78d32.tar.gz gitea-d92b4cd0935fcb7be3fb30253426988aada78d32.zip |
Fix incorrect CLI exit code and duplicate error message (#26346)
Follow the CLI refactoring, and add tests.
Diffstat (limited to 'cmd/main.go')
-rw-r--r-- | cmd/main.go | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/cmd/main.go b/cmd/main.go index 13f9bba013..feda41e68b 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -6,6 +6,7 @@ package cmd import ( "fmt" "os" + "strings" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -117,8 +118,12 @@ func prepareWorkPathAndCustomConf(action cli.ActionFunc) func(ctx *cli.Context) } } -func NewMainApp() *cli.App { +func NewMainApp(version, versionExtra string) *cli.App { app := cli.NewApp() + app.Name = "Gitea" + app.Usage = "A painless self-hosted Git service" + app.Description = `By default, Gitea will start serving using the web-server with no argument, which can alternatively be run by running the subcommand "web".` + app.Version = version + versionExtra app.EnableBashCompletion = true // these sub-commands need to use config file @@ -166,3 +171,18 @@ func NewMainApp() *cli.App { return app } + +func RunMainApp(app *cli.App, args ...string) error { + err := app.Run(args) + if err == nil { + return nil + } + if strings.HasPrefix(err.Error(), "flag provided but not defined:") { + // the cli package should already have output the error message, so just exit + cli.OsExiter(1) + return err + } + _, _ = fmt.Fprintf(app.ErrWriter, "Command error: %v\n", err) + cli.OsExiter(1) + return err +} |