fix(deps): update go dependencies (#38194)

Update go deps and fix discovered issues

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot
2026-06-29 15:10:47 +00:00
committed by GitHub
co-authored by silverwind wxiaoguang
parent 4ce63a1d57
commit 5e5f5f3116
6 changed files with 67 additions and 33 deletions
+12 -1
View File
@@ -203,7 +203,7 @@ func TestCliCmdError(t *testing.T) {
assert.Error(t, err)
assert.Equal(t, 1, r.ExitCode)
assert.Empty(t, r.Stdout)
assert.Equal(t, "Incorrect Usage: flag provided but not defined: -no-such\n\n", r.Stderr)
assert.Equal(t, "Incorrect Usage: flag provided but not defined: -no-such\n", r.Stderr)
app = newTestApp(cli.Command{Action: func(ctx context.Context, cmd *cli.Command) error { return nil }})
r, err = runTestApp(app, "./gitea", "test-cmd")
@@ -235,3 +235,14 @@ func TestCliCmdBefore(t *testing.T) {
assert.Equal(t, "/tmp/any.ini", configValues["before"], "BeforeFunc must be called before preparing config")
assert.Equal(t, "/dev/null", configValues["action"])
}
func TestCliCmdCompletion(t *testing.T) {
app := newTestApp(cli.Command{
Action: func(ctx context.Context, cmd *cli.Command) error { return nil },
})
res, err := runTestApp(app, "./gitea", "completion", "bash", "--nonexist")
assert.Error(t, err)
assert.Equal(t, 1, res.ExitCode)
assert.Equal(t, "", res.Stdout)
assert.Equal(t, "Incorrect Usage: flag provided but not defined: -nonexist\n", res.Stderr)
}
+25 -4
View File
@@ -5,10 +5,10 @@ package cmd
import (
"context"
"errors"
"fmt"
"io"
"os"
"strings"
"gitea.dev/modules/log"
"gitea.dev/modules/setting"
@@ -154,16 +154,37 @@ func NewMainApp(appVer AppVersion) *cli.Command {
return app
}
// usageErr marks a usage error already reported by cliOnUsageError, so RunMainApp does not print it again.
type usageErr struct{ err error }
func (e usageErr) Error() string { return e.err.Error() }
func (e usageErr) Unwrap() error { return e.err }
// cliOnUsageError reports usage errors itself instead of letting urfave/cli dump the full help to stdout (since urfave/cli v3.10).
func cliOnUsageError(_ context.Context, cmd *cli.Command, err error, _ bool) error {
_, _ = fmt.Fprintf(cmd.Root().ErrWriter, "Incorrect Usage: %s\n", err.Error())
return usageErr{err}
}
func setCLIOnUsageError(cmd *cli.Command) {
_ = cmd.Walk(func(c *cli.Command) error {
c.OnUsageError = cliOnUsageError
return nil
})
}
func RunMainApp(app *cli.Command, args ...string) error {
ctx, cancel := installSignals()
defer cancel()
setCLIOnUsageError(app)
// the completion subcommands are built during app.Run, after the Walk above, so cover them via this hook
app.ConfigureShellCompletionCommand = setCLIOnUsageError
err := app.Run(ctx, 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)
if _, ok := errors.AsType[usageErr](err); ok {
cli.OsExiter(1) // cliOnUsageError already reported it
return err
}
_, _ = fmt.Fprintf(app.ErrWriter, "Command error: %v\n", err)