diff --git a/unsloth_cli/__init__.py b/unsloth_cli/__init__.py index 28da00f37b..65834b3b9d 100644 --- a/unsloth_cli/__init__.py +++ b/unsloth_cli/__init__.py @@ -2,17 +2,45 @@ # Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0 import typer +from importlib.metadata import version as package_version, PackageNotFoundError + from unsloth_cli.commands.train import train from unsloth_cli.commands.inference import inference from unsloth_cli.commands.export import export, list_checkpoints from unsloth_cli.commands.studio import run as studio_run, studio_app + +def show_version(value: bool): + if value: + try: + version = package_version("unsloth") + except PackageNotFoundError: + version = "unknown" + typer.echo(f"unsloth {version}") + raise typer.Exit() + + app = typer.Typer( help = "Command-line interface for Unsloth training, inference, and export.", context_settings = {"help_option_names": ["-h", "--help"]}, ) + +@app.callback() +def main( + version: bool = typer.Option( + None, + "--version", + "-V", + callback = show_version, + is_eager = True, + help = "Show version and exit.", + ), +): + pass + + app.command()(train) app.command()(inference) app.command()(export)