Skip to content

Commit c2a52ad

Browse files
committed
add --version
1 parent e8f6713 commit c2a52ad

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Print to stdout instead (e.g. for piping):
3030
pyobfuscate -i your_file.py --stdout
3131
```
3232

33+
Print the installed version (from `python_obfuscator.version`):
34+
35+
```
36+
pyobfuscate --version
37+
```
38+
3339
## More Detailed Documentation
3440

3541
You can use this as a module if you want

python_obfuscator/cli/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import sys
12
from pathlib import Path
23
from typing import Annotated
34

45
import typer
56

67
import python_obfuscator
78
from python_obfuscator.techniques import one_liner as one_liner_technique
9+
from python_obfuscator.version import __version__
810

911
DEFAULT_OUTPUT_DIR = "obfuscated"
1012

@@ -25,6 +27,7 @@ def main(
2527
input_path: Annotated[
2628
Path,
2729
typer.Option(
30+
...,
2831
"--input",
2932
"-i",
3033
help="File to obfuscate",
@@ -49,21 +52,26 @@ def main(
4952
),
5053
] = False,
5154
) -> None:
55+
resolved = input_path.expanduser().resolve()
56+
5257
obfuscate = python_obfuscator.obfuscator()
5358
remove = []
5459
if not include_one_liner:
5560
remove.append(one_liner_technique)
5661

57-
data = input_path.read_text()
62+
data = resolved.read_text()
5863
obfuscated_data = obfuscate.obfuscate(data, remove_techniques=remove)
5964

6065
if stdout:
6166
typer.echo(obfuscated_data)
6267
else:
63-
out_path = _resolved_output_path(input_path)
68+
out_path = _resolved_output_path(resolved)
6469
out_path.write_text(obfuscated_data)
6570
typer.secho(f"Wrote {out_path}", err=True)
6671

6772

6873
def cli() -> None:
74+
if len(sys.argv) == 2 and sys.argv[1] in ("--version", "-V"):
75+
typer.echo(__version__)
76+
raise SystemExit(0)
6977
typer.run(main)

0 commit comments

Comments
 (0)