Skip to content

Commit 5239045

Browse files
inimazbenoit-cty
authored andcommitted
fix (cli): do not show traceback when error
1 parent f12b4a5 commit 5239045

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

codecarbon/cli/main.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,27 @@
4141
codecarbon = typer.Typer(no_args_is_help=True)
4242

4343

44+
def main():
45+
"""
46+
Main entry point for the CodeCarbon CLI application.
47+
This function catches any exceptions raised during the execution of the CLI commands
48+
and prints an error message in red using Rich's print function.
49+
"""
50+
try:
51+
codecarbon()
52+
except Exception as e:
53+
print(f"[bold red]Error:[/bold red] {e}")
54+
raise sys.exit(1)
55+
56+
4457
def _version_callback(value: bool) -> None:
4558
if value:
4659
print(f"{__app_name__} v{__version__}")
4760
raise typer.Exit()
4861

4962

5063
@codecarbon.callback()
51-
def main(
64+
def version(
5265
version: Optional[bool] = typer.Option(
5366
None,
5467
"--version",
@@ -410,4 +423,4 @@ def questionary_prompt(prompt, list_options, default):
410423

411424

412425
if __name__ == "__main__":
413-
codecarbon()
426+
main()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ viz = [
6060

6161
[project.scripts]
6262
carbonboard = "codecarbon.viz.carbonboard:main"
63-
codecarbon = "codecarbon.cli.main:codecarbon"
63+
codecarbon = "codecarbon.cli.main:main"
6464

6565
[tool.hatch.env]
6666
requires = [

0 commit comments

Comments
 (0)