Skip to content

Commit

Permalink
feat(cli): add -V|--version option
Browse files Browse the repository at this point in the history
  • Loading branch information
Niko Heikkilä committed Jan 30, 2022
1 parent fafd8f9 commit db13bcf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ for wheel in dist/*.whl; do
done

echo "Testing executable"
publicator --version
publicator --help
12 changes: 11 additions & 1 deletion publicator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
__version__ = "0.1.0"
from importlib import metadata

name = "publicator"


def display_name() -> str:
return name.capitalize()


def version() -> str:
return f"{display_name()} v{metadata.version(name)}"
15 changes: 13 additions & 2 deletions publicator/cli.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import os
from typing import Optional

import typer

from publicator import git, github, poetry, config
import publicator
from publicator import config, git, github, poetry
from publicator.semver import Semver

preview = os.environ.get("PUBLICATOR_PREVIEW")
configuration = config.factory()
app = typer.Typer(name="publicator")
app = typer.Typer(name=publicator.name)


def version_callback(value: bool) -> None:
if not value:
return

typer.secho(f"🦄 {publicator.version()}", fg=typer.colors.BRIGHT_BLUE, bold=True)
raise typer.Exit()


@app.command()
Expand All @@ -17,6 +27,7 @@ def cli(
metavar="version",
help="can be a valid semver or one of: patch, minor, major, prepatch, preminor, premajor, prerelease",
),
version: Optional[bool] = typer.Option(None, "--version", "-V", callback=version_callback, is_eager=True),
repository: Optional[str] = typer.Option(
default=configuration.get("repository"),
metavar="name",
Expand Down

0 comments on commit db13bcf

Please sign in to comment.