TestCliCmdCompletion

This commit is contained in:
wxiaoguang
2026-06-29 10:01:07 +08:00
parent 06ee69a51f
commit 22439e119b
2 changed files with 13 additions and 3 deletions

View File

@@ -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)
}

View File

@@ -177,9 +177,8 @@ func RunMainApp(app *cli.Command, args ...string) error {
ctx, cancel := installSignals()
defer cancel()
setCLIOnUsageError(app)
// FIXME: why it needs to set ConfigureShellCompletionCommand? What's wrong without it?
// // the completion subcommands are built during app.Run, after the Walk above, so cover them via this hook
// app.ConfigureShellCompletionCommand = setCLIOnUsageError
// 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