Skip to content

Commit 55d43cb

Browse files
committed
Add -v/--version flag to CLI
Add a version flag that displays the package version from importlib.metadata. Both -v and --version are supported. Includes tests for both flags.
1 parent 53cf31c commit 55d43cb

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/claude_code_publish/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Convert Claude Code session JSON to a clean mobile-friendly HTML page with pagination."""
22

3+
import importlib.metadata
34
import json
45
import html
56
import os
@@ -921,6 +922,23 @@ def generate_html(json_path, output_dir, github_repo=None):
921922

922923

923924
@click.group(cls=DefaultGroup, default="session", default_if_no_args=False)
925+
@click.option(
926+
"-v",
927+
"--version",
928+
is_flag=True,
929+
callback=lambda ctx, param, value: (
930+
ctx.exit(
931+
click.echo(
932+
f"claude-code-publish, version {importlib.metadata.version('claude-code-publish')}"
933+
)
934+
)
935+
if value
936+
else None
937+
),
938+
expose_value=False,
939+
is_eager=True,
940+
help="Show the version and exit.",
941+
)
924942
def cli():
925943
"""Convert Claude Code session JSON to mobile-friendly HTML pages."""
926944
pass

tests/test_generate_html.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,32 @@ def mock_run(*args, **kwargs):
871871
assert "gistpreview.github.io" in result.output
872872

873873

874+
class TestVersionOption:
875+
"""Tests for the --version option."""
876+
877+
def test_version_long_flag(self):
878+
"""Test that --version shows version info."""
879+
from click.testing import CliRunner
880+
from claude_code_publish import cli
881+
882+
runner = CliRunner()
883+
result = runner.invoke(cli, ["--version"])
884+
885+
assert result.exit_code == 0
886+
assert "0.2" in result.output
887+
888+
def test_version_short_flag(self):
889+
"""Test that -v shows version info."""
890+
from click.testing import CliRunner
891+
from claude_code_publish import cli
892+
893+
runner = CliRunner()
894+
result = runner.invoke(cli, ["-v"])
895+
896+
assert result.exit_code == 0
897+
assert "0.2" in result.output
898+
899+
874900
class TestOpenOption:
875901
"""Tests for the --open option."""
876902

0 commit comments

Comments
 (0)