Skip to content

Commit fb00677

Browse files
committed
added cli version option
1 parent d8b8f1b commit fb00677

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

ellar_cli/main.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import typing as t
44

55
import click
6+
import ellar
67
import typer
78
from ellar.common.commands import EllarTyper
89
from ellar.common.constants import CALLABLE_COMMAND_INFO, MODULE_METADATA
@@ -11,6 +12,7 @@
1112
from ellar.core.services import Reflector
1213
from typer.models import CommandInfo
1314

15+
import ellar_cli
1416
from ellar_cli.constants import ELLAR_META
1517

1618
from .manage_commands import create_module, create_project, new_command, runserver
@@ -27,6 +29,16 @@
2729
_typer.command(name="create-module")(create_module)
2830

2931

32+
def version_callback(value: bool) -> None:
33+
if value:
34+
click.echo("===========================================================")
35+
click.echo(f"Ellar CLI Version: {ellar_cli.__version__}")
36+
click.echo("-----------------------------------------------------------")
37+
click.echo(f"Ellar Version: {ellar.__version__}")
38+
click.echo("===========================================================")
39+
raise typer.Exit(0)
40+
41+
3042
@_typer.callback()
3143
def typer_callback(
3244
ctx: typer.Context,
@@ -38,6 +50,14 @@ def typer_callback(
3850
exists=True,
3951
help="Run Specific Command on a specific project",
4052
),
53+
version: t.Optional[bool] = typer.Option(
54+
...,
55+
"-v",
56+
"--version",
57+
callback=version_callback,
58+
is_flag=True,
59+
help="CLI Version",
60+
),
4161
) -> None:
4262
meta_: t.Optional[EllarCLIService] = EllarCLIService.import_project_meta(project)
4363
ctx.meta[ELLAR_META] = meta_
@@ -49,8 +69,8 @@ def build_typers() -> t.Any: # pragma: no cover
4969
argv = list(sys.argv)
5070
options, args = getopt.getopt(
5171
argv[1:],
52-
"hp:",
53-
["project=", "help"],
72+
"hpv:",
73+
["project=", "help", "version"],
5474
)
5575
for k, v in options:
5676
if k in ["-p", "--project"] and v:

tests/test_ellar_cli_service.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,13 @@ def test_import_root_module_works(write_empty_py_project, process_runner):
170170
root_module = ellar_cli_service.import_root_module()
171171

172172
assert issubclass(root_module, ModuleBase)
173+
174+
175+
def test_version_works(write_empty_py_project, process_runner):
176+
result = process_runner(["ellar", "--version"])
177+
assert result.returncode == 0
178+
179+
assert (
180+
result.stdout
181+
== b"===========================================================\nEllar CLI Version: 0.2.2\n-----------------------------------------------------------\nEllar Version: 0.4.7\n===========================================================\n"
182+
)

0 commit comments

Comments
 (0)