Skip to content

Commit 573a369

Browse files
Add --version flag to display client version
- Add --version argument to display 'codeplain version X.X.X' - Update filename validation to allow --version without filename - Add unit test for --version flag - Version flag takes precedence (checked first in main())
1 parent eed0d3e commit 573a369

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

cli_output/status.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ def print_status(api_key: str, api_url: str, client_version: str) -> None:
133133
console.print(f"Version: {client_version}")
134134
else:
135135
from plain2code_console import Plain2CodeConsole
136-
console.print(f"Version: {client_version} (outdated — minimum required: {min_version})", style=Plain2CodeConsole.ERROR_STYLE)
136+
137+
console.print(
138+
f"Version: {client_version} (outdated — minimum required: {min_version})",
139+
style=Plain2CodeConsole.ERROR_STYLE,
140+
)
137141
console.print("To update, run: uv tool upgrade codeplain\n", style=Plain2CodeConsole.ERROR_STYLE)
138142
console.print(f"Name: {user['first_name']} {user['last_name']}")
139143
console.print(f"User email: {user['email']}")

plain2code.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
get_log_file_path,
4848
)
4949
from plain2code_state import RunState
50-
from plain2code_utils import format_duration_hms
5150
from system_config import system_config
5251
from tui.plain2code_tui import Plain2CodeTUI
5352
from tui.plain_module_render_choice_tui import PlainModuleRenderChoiceTUI
@@ -254,6 +253,11 @@ def main(): # noqa: C901
254253

255254
args = parse_arguments()
256255

256+
# Handle --version flag before any other initialization
257+
if args.version:
258+
console.print(f"codeplain version {system_config.client_version}")
259+
return
260+
257261
# Handle --status flag before any other initialization
258262
if args.status:
259263
if not args.api_key:

plain2code_arguments.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,13 @@ def create_parser():
357357
"Does not render any code.",
358358
)
359359

360+
parser.add_argument(
361+
"--version",
362+
action="store_true",
363+
default=False,
364+
help="Display the client version and exit.",
365+
)
366+
360367
return parser
361368

362369

@@ -366,7 +373,7 @@ def parse_arguments():
366373
args = parser.parse_args()
367374

368375
# Validate filename is provided when needed
369-
if not args.status and not args.filename:
376+
if not args.status and not args.version and not args.filename:
370377
parser.error("the following arguments are required: filename")
371378

372379
# Only process config if filename is provided (not needed for --status)

tests/test_cli_output.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Unit tests for cli_output module."""
22

33
from datetime import datetime, timezone
4+
from io import StringIO
45
from unittest.mock import Mock, patch
56

67
import pytest
@@ -386,3 +387,25 @@ def test_multiple_purchased_credit_buckets(self, mock_console, mock_api_class):
386387
calls = [str(call) for call in mock_console.print.call_args_list]
387388
purchased_calls = [c for c in calls if "Purchased" in c]
388389
assert len(purchased_calls) == 2
390+
391+
392+
class TestVersionFlag:
393+
"""Tests for --version flag."""
394+
395+
def test_version_flag_without_filename(self, capsys):
396+
"""Test that --version works without providing a filename."""
397+
import sys
398+
399+
import plain2code
400+
401+
# Save original argv
402+
original_argv = sys.argv
403+
try:
404+
sys.argv = ["plain2code.py", "--version"]
405+
# This should not raise an error about missing filename
406+
plain2code.main()
407+
408+
captured = capsys.readouterr()
409+
assert "codeplain version" in captured.out
410+
finally:
411+
sys.argv = original_argv

0 commit comments

Comments
 (0)