Skip to content

Commit 8869590

Browse files
committed
feat(cli): add version command line flag to display version.
1 parent 39ba033 commit 8869590

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

unblob/cli.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ def restore_cursor():
3535
sys.stdout.write("\033[?25h") # ANSI escape code to show cursor
3636

3737

38+
def get_version():
39+
return pkg_resources.get_distribution("unblob").version
40+
41+
42+
def show_version(
43+
ctx: click.Context, _param: click.Option, value: bool # noqa: FBT001
44+
) -> None:
45+
if not value or ctx.resilient_parsing:
46+
return
47+
click.echo(get_version())
48+
ctx.exit(code=0)
49+
50+
3851
def show_external_dependencies(
3952
ctx: click.Context, _param: click.Option, value: bool # noqa: FBT001
4053
) -> None:
@@ -198,6 +211,13 @@ def __init__(
198211
callback=show_external_dependencies,
199212
expose_value=False,
200213
)
214+
@click.option(
215+
"--version",
216+
help="Shows unblob version",
217+
is_flag=True,
218+
callback=show_version,
219+
expose_value=False,
220+
)
201221
def cli(
202222
file: Path,
203223
extract_root: Path,

0 commit comments

Comments
 (0)