Add a simple --version flag (#5516)

* Add a simple --version flag

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Small code clean-up, less ugly

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Slightly better function names. And use again None

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Roland Tannous <115670425+rolandtannous@users.noreply.github.com>
This commit is contained in:
Melroy van den Berg 2026-05-18 02:04:05 +02:00 committed by GitHub
commit f7bd05ad13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)