Skip to content

Suppress "Succeeded" line after vendir completion output - #457

Open
pujitha24 wants to merge 1 commit into
carvel-dev:developfrom
pujitha24:auto/issue-405
Open

Suppress "Succeeded" line after vendir completion output#457
pujitha24 wants to merge 1 commit into
carvel-dev:developfrom
pujitha24:auto/issue-405

Conversation

@pujitha24

Copy link
Copy Markdown

Motivation:
vendir completion bash (and zsh/fish/powershell) prints a shell
script to stdout that is meant to be sourced or eval'd directly, e.g.
source <(vendir completion bash). main() unconditionally printed a
trailing "Succeeded" line after every command, including completion,
so the sourced script ended with a bare Succeeded token, which the
shell then tried to execute as a command.

Approach:
main() now captures the actually-executed *cobra.Command via
command.ExecuteC() (Execute() is just ExecuteC() with the command
discarded, so this is behavior-preserving for every other command)
and skips the "Succeeded" line when the executed command is cobra's
built-in "completion" command or one of its bash/zsh/fish/powershell
subcommands. vendir does not define its own completion command, so
this only affects cobra's default completion tree.

An initial attempt mirrored the fix already applied in carvel-dev/kapp
(cmd/kapp/kapp.go), which guards the same print with
cobrautil.IsCobraManagedCommand(os.Args). Building and testing that
approach against this issue showed it does not actually suppress the
line for completion bash: IsCobraManagedCommand only special-cases
"help", "__complete" and "__completeNoDesc", not "completion" itself,
so it does not resolve this report.

Validation:

  • go build ./...
  • ./hack/test.sh (repo's documented unit test script) - all packages
    pass; this code path has no existing unit tests.
  • ./hack/build.sh (repo's documented build script: go mod
    vendor/tidy, go fmt, real build, ./vendir version, compile-only
    go test --exec=echo ./...) - all steps pass.
  • Manually built the binary before and after the change and compared:
    vendir completion bash|zsh|fish|powershell | tail -n 3 no longer
    ends with "Succeeded" (it did before), while vendir version and
    an error path (vendir sync -f /nonexistent.yml, exit 1) are
    unaffected and still print/omit "Succeeded" as before.
  • bash -c 'source <(vendir completion bash) && echo SOURCE_OK'
    succeeds after the fix, reproducing and resolving the exact failure
    mode from the report (it fails without the fix, since the shell
    tries to run the stray Succeeded token as a command).

User-visible behavior for every non-completion command is unchanged.

Report: #405
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com

Fixes #405

Motivation:
`vendir completion bash` (and zsh/fish/powershell) prints a shell
script to stdout that is meant to be sourced or eval'd directly, e.g.
`source <(vendir completion bash)`. main() unconditionally printed a
trailing "Succeeded" line after every command, including completion,
so the sourced script ended with a bare `Succeeded` token, which the
shell then tried to execute as a command.

Approach:
main() now captures the actually-executed *cobra.Command via
command.ExecuteC() (Execute() is just ExecuteC() with the command
discarded, so this is behavior-preserving for every other command)
and skips the "Succeeded" line when the executed command is cobra's
built-in "completion" command or one of its bash/zsh/fish/powershell
subcommands. vendir does not define its own completion command, so
this only affects cobra's default completion tree.

An initial attempt mirrored the fix already applied in carvel-dev/kapp
(cmd/kapp/kapp.go), which guards the same print with
cobrautil.IsCobraManagedCommand(os.Args). Building and testing that
approach against this issue showed it does not actually suppress the
line for `completion bash`: IsCobraManagedCommand only special-cases
"help", "__complete" and "__completeNoDesc", not "completion" itself,
so it does not resolve this report.

Validation:
- go build ./...
- ./hack/test.sh (repo's documented unit test script) - all packages
  pass; this code path has no existing unit tests.
- ./hack/build.sh (repo's documented build script: go mod
  vendor/tidy, go fmt, real build, `./vendir version`, compile-only
  `go test --exec=echo ./...`) - all steps pass.
- Manually built the binary before and after the change and compared:
  `vendir completion bash|zsh|fish|powershell | tail -n 3` no longer
  ends with "Succeeded" (it did before), while `vendir version` and
  an error path (`vendir sync -f /nonexistent.yml`, exit 1) are
  unaffected and still print/omit "Succeeded" as before.
- `bash -c 'source <(vendir completion bash) && echo SOURCE_OK'`
  succeeds after the fix, reproducing and resolving the exact failure
  mode from the report (it fails without the fix, since the shell
  tries to run the stray `Succeeded` token as a command).

User-visible behavior for every non-completion command is unchanged.

Report: carvel-dev#405
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 4, 2026 22:45
@carvel-bot carvel-bot added this to Carvel Aug 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes vendir completion <shell> output so it can be safely sourced/eval’d by suppressing the trailing Succeeded line after completion script generation, addressing the reported Succeeded token execution error (Fixes #405).

Changes:

  • Switches from command.Execute() to command.ExecuteC() to capture the executed Cobra command.
  • Skips printing Succeeded when the executed command is Cobra’s completion command (or its shell subcommands).
  • Adds a small helper (isCompletionCmd) to detect when the executed command is part of the completion command tree.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/vendir/vendir.go
Comment on lines +46 to 48
func isCompletionCmd(c *cobra.Command) bool {
return c.Name() == "completion" || (c.HasParent() && c.Parent().Name() == "completion")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

vendir completion outputs superflous "Succeeded"

3 participants