From 8629003d9bcca7dfb9d9d0b0b21d0e8737d28857 Mon Sep 17 00:00:00 2001 From: Tsvika S Date: Mon, 11 Nov 2024 15:13:30 +0200 Subject: [PATCH] feature: add --version --- nbcat/__main__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nbcat/__main__.py b/nbcat/__main__.py index 787677f..e54e4d8 100644 --- a/nbcat/__main__.py +++ b/nbcat/__main__.py @@ -2,7 +2,7 @@ import re from pathlib import Path -from typing import Annotated +from typing import Annotated, Optional import nbconvert import nbformat @@ -11,6 +11,8 @@ from pygments import lexers from pygments.formatters import terminal +from . import __version__ + SUPPORTED_FORMATS = { # each entry is a tuple of the exporter class and the lexer name "md": (nbconvert.exporters.MarkdownExporter, "markdown"), @@ -25,6 +27,12 @@ app = typer.Typer() +def version_callback(value: bool) -> None: # noqa: FBT001, D103 + if value: + print(f"nbcat {__version__}") # noqa: T201 + raise typer.Exit() # noqa: RSE102 + + @app.command() def main( filename: Annotated[ @@ -55,6 +63,10 @@ def main( help="Force syntax highlighting even when the output is not a terminal", ), ] = False, + version: Annotated[ # noqa: ARG001 + Optional[bool], # noqa: FA100 + typer.Option("--version", callback=version_callback, is_eager=True), + ] = None, ) -> None: """Display a notebook with syntax highlighting in the terminal.""" # set the exporter and laxer name based on the format