Skip to content

Commit eda5703

Browse files
committed
Add --version flag to pf command
1 parent c25f8e4 commit eda5703

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ body:
6767
id: version
6868
attributes:
6969
label: PostForge version
70-
description: Run `pf` and check the version in the startup banner.
70+
description: Run `pf --version`.
7171
validations:
7272
required: false
7373

postforge/cli_args.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import argparse
1313
import os
14+
import re
1415

1516

1617
def _parse_page_ranges(spec: str) -> set:
@@ -87,6 +88,18 @@ def get_output_base_name(outputfile: str, inputfiles: list) -> str:
8788
return "page"
8889

8990

91+
def _get_version() -> str:
92+
"""Read the PostForge version from sysdict.ps (sole source of truth)."""
93+
sysdict = os.path.join(os.path.dirname(os.path.abspath(__file__)),
94+
os.pardir, "resources", "Init", "sysdict.ps")
95+
with open(sysdict, "r") as f:
96+
for line in f:
97+
m = re.search(r'/revisionstring\s+\(([^)]+)\)', line)
98+
if m:
99+
return m.group(1)
100+
return "unknown"
101+
102+
90103
def build_argument_parser(available_devices: list) -> argparse.ArgumentParser:
91104
"""
92105
Create and configure the PostForge argument parser.
@@ -103,6 +116,10 @@ def build_argument_parser(available_devices: list) -> argparse.ArgumentParser:
103116
epilog="If no input file is provided, PostForge will run in interactive mode.",
104117
)
105118

119+
parser.add_argument(
120+
"-V", "--version", action="version",
121+
version=f"PostForge {_get_version()}"
122+
)
106123
parser.add_argument("inputfiles", nargs="*", help="PostScript input files to process (each as separate job)")
107124
parser.add_argument(
108125
"-o", "--output", dest="outputfile", help="Specify output filename"

0 commit comments

Comments
 (0)