diff --git a/contree_cli/cli/ps.py b/contree_cli/cli/ps.py index b6e5b00..2d593a2 100644 --- a/contree_cli/cli/ps.py +++ b/contree_cli/cli/ps.py @@ -40,7 +40,7 @@ class PsArgs(ArgumentsProtocol): quiet: bool = False all: bool = False show_max: int | None = None - status: str = "EXECUTING" + status: str | None = None kind: str | None = None since: datetime | None = None until: datetime | None = None @@ -82,8 +82,8 @@ def setup_parser(p: argparse.ArgumentParser) -> SetupResult: p.add_argument( *FLAGS["status"], choices=tuple(itertools.chain.from_iterable(STATUS_CHOICES.items())), - default="EXECUTING", - help="Filter by status", + default=None, + help="Filter by status (default: EXECUTING only, unless -a is used)", ) p.add_argument( *FLAGS["kind"], @@ -174,11 +174,13 @@ def cmd_ps(args: PsArgs) -> None: formatter: OutputFormatter = FORMATTER.get() status: str | None = None - if not args.all: + if args.status is not None: if len(args.status) == 1: status = STATUS_CHOICES.get(args.status, args.status) else: status = args.status + elif not args.all: + status = "EXECUTING" since: str | None = None if args.since is not None: diff --git a/tests/test_ps.py b/tests/test_ps.py index 31ec4b4..4d28204 100644 --- a/tests/test_ps.py +++ b/tests/test_ps.py @@ -182,6 +182,13 @@ def test_all_flag_no_status_param(self, contree_client): _run_cmd(contree_client, ops, all=True) assert "status=" not in contree_client.request_paths[0] + def test_all_with_explicit_status(self, contree_client, capsys): + """--all combined with --status sends the status filter.""" + ops = [_make_op(0, status="FAILED")] + _run_cmd(contree_client, ops, all=True, status="FAILED") + assert "status=FAILED" in contree_client.request_paths[0] + assert "op-0" in capsys.readouterr().out + @pytest.mark.parametrize( "short,full", list(STATUS_CHOICES.items()),