Let ci status subcommand exit without input, with a useful exit code, ideally for a specific job
<!---
Please read this!
Before opening a new issue, make sure to search for keywords in the issues
filtered by the "feature" label:
- https://gitlab.com/gitlab-org/cli/-/issues/?label_name%5B%5D=type%3A%3Afeature
and verify the issue you're about to submit isn't a duplicate.
--->
### Problem to solve
When waiting for CI, I'd like to be able to get the status (of a pipeline or of a specific job) rather than watching the output for changes and then being prompted to "Choose an action". This would be really useful to enable terminal pipelines such as:
```
glab ci status --wait && glab job artifact some_branch some_job && say "Ready to test"
```
### Proposal
I'd love to see a flag, `--wait`, added to the ci status subcommand. Ideally I'd like it to wait for the entire pipeline to finish, then return a 0 status if all required jobs were successful and some other exit code (perhaps the number of failed jobs) if they did not all pass.
Additionally, it would be great to have `--wait=job_name` available with similar behavior, but exiting from the command as soon as that job finishes. In this case, I'd only want the exit status to consider that job, so `--wait=build_linux` would exit 0 if build_linux had succeeded, even if build_mac had failed and/or build_windows hadn't completed (or even been started) yet.
It could be useful to have `--quiet` as well such that the output is silenced and no "survey" is performed, but the command simply "idles" until all jobs (in the absence of `--wait` or when `--wait` is not provided an argument) or a specific job (with `--wait=job_name`) has completed.
In any case here, when `--wait` or `--quiet` if we add that as well are passed, no "Choose an action" survey would be performed, as in the case of `--wait` the point is to pause execution of some script or pipeline until the job has been completed, and with `--quiet` there would not be output (or input) expected.
#### Alternative
I'm not sure what the current exit status looks like, but the bare `--wait` and `--quiet` requests could be solved by some version of a `--no-ask` or even `--then=[logs|retry-failed|exit]` flag such that `glab ci status --live --compact --then=exit` provided CI output as normal then exits as soon as all jobs complete. The `--quiet` use-case could be accomplished by `>/dev/null`. This would _not_ satisfy the `--wait=<some_job>` use-case of short-circuiting the exit time.
<!-- implementation plan added during 2026-09 backlog triage -->
## Implementation plan
> **Note:** This plan was drafted during an AI-assisted triage of the backlog and has not been validated by a maintainer. Treat it as a starting point: file paths, line numbers, and the approach may need adjusting.
1. **Make `--wait` accept an optional job name.** In `internal/commands/ci/status/status.go`, replace the `BoolP("wait", "w", false, ...)` registration (status.go:302) with `StringP("wait", "w", "", ...)` and set `pipelineStatusCmd.Flags().Lookup("wait").NoOptDefVal = "true"` so a bare `--wait` still means "wait for the whole pipeline". `internal/cmdutils/bool_flag_pair.go:15` is the existing `NoOptDefVal` precedent in this repo. Note in the flag description that the value form is `--wait=<job_name>` or `-w<job_name>`: with `NoOptDefVal` set, cobra does not consume a space-separated `--wait <job_name>`.
2. **Thread the value through the `RunE` gates.** Change `wait, _ := cmd.Flags().GetBool("wait")` (status.go:80) to `GetString("wait")`, update the `--output json` incompatibility check (status.go:82) to test `wait != ""`, and change `if wait { live = true; opts.io.SetPrompt("true") }` (status.go:86) to the same `wait != ""` condition. Derive a `waitJob` string that is empty when `wait` is `""` or `"true"`, and the job name otherwise.
3. **Short-circuit the poll loop on the named job.** Add an `isTerminalJobStatus(status string) bool` helper next to `isLivePollableStatus` (status.go:308) covering `success`, `failed`, `canceled`, `skipped`, and `manual`. Inside the render loop, after the `ListPipelineJobs` call and the per-job render (status.go:143-181), when `waitJob != ""` look for a job whose `Name` matches, and when it has a terminal status, record it and `break loop` instead of waiting for the rest of the pipeline.
4. **Scope the exit code to that job.** At the end of `RunE` (status.go:292-295), keep `return cmdutils.SilentError` on a failed pipeline only when `waitJob == ""`. When a job name was given, return `cmdutils.SilentError` if that job finished `failed` and `AllowFailure` is false, and `nil` otherwise, so an unrelated failing job does not change the exit code. If the pipeline reaches a terminal state and the named job never appeared, return a normal error naming the job.
5. **Extend the tests.** Add cases to `internal/commands/ci/status/status_test.go`, modeled on `TestCiStatusCommand_Wait_NoPrompt` (status_test.go:272), which uses `gitlabtesting.NewTestClient` for the mocked API and `cmdtest.SetupCmdForTest(t, NewCmdStatus, ...)` with `cmdtest.WithGitLabClient` and `cmdtest.WithBranch`. Cover: `--wait=build_linux` exits 0 when `build_linux` succeeded while another job in the same pipeline failed; `--wait=build_linux` returns `cmdutils.SilentError` when `build_linux` itself failed; a job name absent from the pipeline returns the naming error; bare `--wait` keeps its current behavior; `--output json --wait=build_linux` still returns the existing incompatibility error.
6. **Regenerate the docs.** Update the `Example` block and the `--wait` flag description on the `cobra.Command` in `NewCmdStatus`, run `make gen-docs`, and commit the regenerated `docs/source/ci/status.md` in the same commit. Never edit `docs/source/` by hand.
issue
GitLab AI Context
Project: gitlab-org/cli
Instance: https://gitlab.com
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://gitlab.com/gitlab-org/cli/-/raw/main/CONTRIBUTING.md — contribution guidelines
- https://gitlab.com/gitlab-org/cli/-/raw/main/README.md — project overview and setup
- https://gitlab.com/gitlab-org/cli/-/raw/main/AGENTS.md — AI agent instructions
- https://gitlab.com/gitlab-org/cli/-/raw/main/CLAUDE.md — Claude Code instructions
Repository: https://gitlab.com/gitlab-org/cli
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD