Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

feat(cli): optionally hide version splash (#3329)

Jérome Eertmans018e4a3c1a7c
diff --git a/manim/__main__.py b/manim/__main__.py
index 7b57cc54a..c11ca8845 100644
--- a/manim/__main__.py
+++ b/manim/__main__.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import sys
+import click
import cloup
from . import __version__, cli_ctx_settings, console
@@ -14,12 +15,15 @@ from .cli.render.commands import render
from .constants import EPILOG
-def exit_early(ctx, param, value):
+def show_splash(ctx, param, value):
if value:
- sys.exit()
+ console.print(f"Manim Community [green]v{__version__}[/green]\n")
-console.print(f"Manim Community [green]v{__version__}[/green]\n")
+def print_version_and_exit(ctx, param, value):
+ show_splash(ctx, param, value)
+ if value:
+ ctx.exit()
@cloup.group(
@@ -37,7 +41,16 @@ console.print(f"Manim Community [green]v{__version__}[/green]\n")
"--version",
is_flag=True,
help="Show version and exit.",
- callback=exit_early,
+ callback=print_version_and_exit,
+ is_eager=True,
+ expose_value=False,
+)
+ "--show-splash/--hide-splash",
+ is_flag=True,
+ default=True,
+ help="Print splash message with version information.",
+ callback=show_splash,
is_eager=True,
expose_value=False,
)
diff --git a/tests/interface/test_commands.py b/tests/interface/test_commands.py
index 92444f703..fce3efde8 100644
--- a/tests/interface/test_commands.py
+++ b/tests/interface/test_commands.py
@@ -28,7 +28,9 @@ def test_manim_cfg_subcommand():
command = ["cfg"]
runner = CliRunner()
result = runner.invoke(main, command, prog_name="manim")
- expected_output = """\
+ expected_output = f"""\
+Manim Community v{__version__}
+
Usage: manim cfg [OPTIONS] COMMAND [ARGS]...
Manages Manim configuration files.
@@ -50,7 +52,9 @@ def test_manim_plugins_subcommand():
command = ["plugins"]
runner = CliRunner()
result = runner.invoke(main, command, prog_name="manim")
- expected_output = """\
+ expected_output = f"""\
+Manim Community v{__version__}
+
Usage: manim plugins [OPTIONS]
Manages Manim plugins.
@@ -90,7 +94,9 @@ def test_manim_init_subcommand():
command = ["init"]
runner = CliRunner()
result = runner.invoke(main, command, prog_name="manim")
- expected_output = """\
+ expected_output = f"""\
+Manim Community v{__version__}
+
Usage: manim init [OPTIONS] COMMAND [ARGS]...
Create a new project or insert a new scene.