Skip to content

Commit af298c3

Browse files
authored
bug: fixing version flag handling in CLI (#169)
1 parent dc9353b commit af298c3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/sugar/cli.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ def _check_sugar_file(file_path: str = '.sugar.yaml') -> bool:
7070
return Path(file_path).exists()
7171

7272

73-
def version_callback() -> None:
74-
"""Print the Sugar version."""
75-
SugarLogs.print_info(f'Sugar version: {__version__}')
73+
def version_callback(value: bool) -> None:
74+
"""Print the Sugar version and exit if flag is set."""
75+
if value:
76+
SugarLogs.print_info(f'Sugar version: {__version__}')
77+
raise typer.Exit()
7678

7779

7880
@app.callback(invoke_without_command=True)
@@ -89,10 +91,11 @@ def main(
8991
help='Set the profile of services for running the sugar command.',
9092
),
9193
version: bool = Option(
92-
None,
94+
False,
9395
'--version',
9496
'-v',
9597
is_flag=True,
98+
callback=version_callback,
9699
is_eager=True,
97100
help='Show the version of sugar.',
98101
),

0 commit comments

Comments
 (0)