Skip to content

Commit

Permalink
feature: add --version
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsvika S committed Nov 11, 2024
1 parent 92af9a8 commit 8629003
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion nbcat/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import re
from pathlib import Path
from typing import Annotated
from typing import Annotated, Optional

import nbconvert
import nbformat
Expand All @@ -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"),
Expand All @@ -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[
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8629003

Please sign in to comment.