From 005464a000f10f558e161e82d670a83455e32878 Mon Sep 17 00:00:00 2001 From: Aleksandr Shpak Date: Sun, 13 Nov 2022 23:36:28 +0300 Subject: [PATCH] feat: add version command (#21) --- .github/workflows/build.yml | 25 ++++-------- .github/workflows/pypi.yml | 2 +- makeqr/__init__.py | 3 ++ makeqr/cli_app.py | 40 +++++++++++++++++-- makeqr/version.py | 1 + pyproject.toml | 2 +- readme.md | 79 +++++++++++++++++++++---------------- 7 files changed, 94 insertions(+), 58 deletions(-) create mode 100644 makeqr/version.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3668f2b..0db5dad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,12 +10,8 @@ jobs: env: REGISTRY_HOST: ghcr.io steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Extract branch name - shell: bash + - uses: actions/checkout@v2 + - shell: bash run: | echo "##[set-output name=name;]$(echo ${GITHUB_REPOSITORY#*/})" echo "##[set-output name=ver;]$(echo ${GITHUB_REF#refs/*/})" @@ -23,22 +19,15 @@ jobs: echo "##[set-output name=major_ver;]$(TMP_VAR=${GITHUB_REF#refs/*/}; echo ${TMP_VAR%.*.*})" echo "##[set-output name=sha;]$(git rev-parse --short "$GITHUB_SHA")" id: extract_name_and_version - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to ${{ env.REGISTRY_HOST }} - uses: docker/login-action@v1 + - uses: docker/setup-qemu-action@v1 + - uses: docker/setup-buildx-action@v1 + - uses: docker/login-action@v1 with: registry: ${{ env.REGISTRY_HOST }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v2 + - run: sed -i 's/0.1.0/'"${{ steps.extract_name_and_version.outputs.ver }}"'/' makeqr/version.py + - uses: docker/build-push-action@v2 with: context: . file: ./Dockerfile diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 6b3fd52..9c11217 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -24,7 +24,7 @@ jobs: echo "##[set-output name=sha;]$(git rev-parse --short "$GITHUB_SHA")" id: extract_name_and_version - run: sed -i 's/0.1.0/'"${{ steps.extract_name_and_version.outputs.ver }}"'/' pyproject.toml - - run: head -n 3 pyproject.toml + - run: sed -i 's/0.1.0/'"${{ steps.extract_name_and_version.outputs.ver }}"'/' makeqr/version.py - run: python -m pip install poetry==1.2.2 - run: poetry build - run: poetry config http-basic.pypi ${{ secrets.PYPI_LOGIN }} ${{ secrets.PYPI_PASS }} diff --git a/makeqr/__init__.py b/makeqr/__init__.py index e5b5e13..02e498f 100644 --- a/makeqr/__init__.py +++ b/makeqr/__init__.py @@ -9,7 +9,9 @@ QRWiFiModel, ) from makeqr.typing import QRDataModelType +from makeqr.version import VERSION +__version__ = VERSION __all__ = ( "MakeQR", "QRDataModelType", @@ -20,4 +22,5 @@ "QRTelModel", "QRTextModel", "QRWiFiModel", + "VERSION", ) diff --git a/makeqr/cli_app.py b/makeqr/cli_app.py index 044dc35..f4e06f2 100644 --- a/makeqr/cli_app.py +++ b/makeqr/cli_app.py @@ -7,6 +7,7 @@ from pydantic import BaseModel, ValidationError from makeqr import ( + VERSION, MakeQR, QRDataModelType, QRGeoModel, @@ -28,6 +29,15 @@ QRTextModel, QRWiFiModel, ) +_CAPTION = ( + " __ __ _______ ___ _ _______ _______ ______\n" + "| |_| || _ || | | || || || _ |\n" + "| || |_| || |_| || ___|| _ || | ||\n" + "| || || _|| |___ | | | || |_||_\n" + "| || || |_ | ___|| |_| || __ |\n" + "| ||_|| || _ || _ || |___ | | | | | |\n" + "|_| |_||__| |__||___| |_||_______||____||_||___| |_|" +) class FieldExtraClickOptionsModel(BaseModel, arbitrary_types_allowed=True): @@ -46,6 +56,7 @@ def _echo_qr( verbose: bool, qr: MakeQR, ) -> None: + click.echo() matrix = qr.matrix if verbose: click.echo(click.style("Result".upper(), bold=True)) @@ -107,8 +118,9 @@ def _echo( **kwargs: Any, ) -> None: if verbose is True: + click.echo() click.echo(click.style(title.upper(), bold=True)) - click.echo(f" {message}", **kwargs) + click.echo(f"{message}", **kwargs) def _add_qr_model_command( @@ -123,13 +135,15 @@ def func( **kwargs: Any, ) -> None: verbose = group_params["verbose"] + if verbose: + click.echo(_CAPTION) try: model: QRDataModelType = model_cls(**kwargs) except ValidationError as err: _echo(verbose, "error", str(err), color=True, err=True) sys.exit(1) _echo(verbose, "Data model", model.json()) - _echo(verbose, "Encoded QR data", model.qr_data) + _echo(verbose, "QR string", model.qr_data) qr = MakeQR( model, box_size=group_params["box-size"], @@ -174,6 +188,17 @@ def _add_commands( _add_qr_model_command(group, model) # type: ignore +def _echo_version( + ctx: click.Context, + param: bool, # noqa, pylint: disable=unused-argument + value: str, +) -> None: + if not value or ctx.resilient_parsing: + return + click.echo(VERSION) + ctx.exit() + + @click.group() @click.option( "--box-size", @@ -208,14 +233,21 @@ def _add_commands( "-q", is_flag=True, default=False, - show_default=True, ) @click.option( "--print", "-p", is_flag=True, default=False, - show_default=True, +) +@click.option( + "--version", + "-V", + is_flag=True, + default=False, + expose_value=False, + is_eager=True, + callback=_echo_version, ) @click.pass_context def cli_group( diff --git a/makeqr/version.py b/makeqr/version.py new file mode 100644 index 0000000..1cf6267 --- /dev/null +++ b/makeqr/version.py @@ -0,0 +1 @@ +VERSION = "0.1.0" diff --git a/pyproject.toml b/pyproject.toml index 0d58212..81f6a07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "makeqr" +name = "MakeQR" version = "0.1.0" description = "Generate QR cards for any occasion" authors = ["Aleksandr Shpak "] diff --git a/readme.md b/readme.md index 43e3077..d6fe1f1 100644 --- a/readme.md +++ b/readme.md @@ -18,7 +18,7 @@ makeqr --help or -``` +```bash makeqr wifi --help ``` @@ -32,42 +32,53 @@ makeqr -p wifi --ssid ABC --password Tfsjfklasdjfklasdest -s wpa2 ### Output -``` +```plain + __ __ _______ ___ _ _______ _______ ______ +| |_| || _ || | | || || || _ | +| || |_| || |_| || ___|| _ || | || +| || || _|| |___ | | | || |_||_ +| || || |_ | ___|| |_| || __ | +| ||_|| || _ || _ || |___ | | | | | | +|_| |_||__| |__||___| |_||_______||____||_||___| |_| + DATA MODEL - {"ssid": "ABC", "security": "wpa2", "password": "Tfsjfklasdjfklasdest", "hidden": false} -ENCODED QR DATA - WIFI:S:ABC;P:Tfsjfklasdjfklasdest;T:WPA;; +{"ssid": "ABC", "security": "wpa2", "password": "Tfsjfklasdjfklasdest", "hidden": false} + +QR STRING +WIFI:S:ABC;P:Tfsjfklasdjfklasdest;T:WPA;; + RESULT + + ██████████████ ████ ██████ ██████ ██████████████ + ██ ██ ██ ██████████ ██ ██ ██ + ██ ██████ ██ ██████ ██ ██ ████ ██ ██████ ██ + ██ ██████ ██ ██ ██ ██ ████ ██ ██ ██████ ██ + ██ ██████ ██ ██ ██ ██ ████████ ██ ██████ ██ + ██ ██ ██ ██████ ██ ████ ██ ██ ██ + ██████████████ ██ ██ ██ ██ ██ ██ ██ ██████████████ + ██ ██████ ████ ██ + ██ ██████████ ██ ████████ ██████████ + ██ ██ ██ ██ ██ ████ ██████ ██ ██ ████ + ██ ██ ████████ ████ ██████ ████ ████ + ██████ ██ ██ ██ ██ ██ ██ ██████ ██ ████ + ██ ██ ████ ██ ██ ████ ██ ████████ + ██ ██ ██████ ██████ ████████ ████ ████ + ██ ████ ████ ██████ ██ ██ ████ ██ ██ ██ + ████ ████ ██ ██████ ██ ██ ██ + ██████ ██ ████████████ ██████ ██ ██ ██ ████ + ██ ████ ██ ████ ██████████████ ██ ██ + ██ ██ ████ ██ ████ ████ ██ ████ + ██ ██████ ██████ ██ ██████████ ██ ██ + ██ ████ ██████ ████ ██████ ██████████████ + ██ ██ ██ ██ ██ ██ ██ ██ + ██████████████ ██ ██████████ ██████ ██ ██ ██ + ██ ██ ████ ██ ██ ████ ████ ████ + ██ ██████ ██ ██ ██ ████ ██ ██████████ ████ + ██ ██████ ██ ██ ████ ██ ██ ██ ████ + ██ ██████ ██ ██ ██ ████ ████ ██ ████████ ██ + ██ ██ ██ ██ ██████ ████ ██ ██ + ██████████████ ██ ██ ██ ██ ██ ██ ██ - ██████████████ ████ ██████ ██████ ██████████████ - ██ ██ ██ ██████████ ██ ██ ██ - ██ ██████ ██ ██████ ██ ██ ████ ██ ██████ ██ - ██ ██████ ██ ██ ██ ██ ████ ██ ██ ██████ ██ - ██ ██████ ██ ██ ██ ██ ████████ ██ ██████ ██ - ██ ██ ██ ██████ ██ ████ ██ ██ ██ - ██████████████ ██ ██ ██ ██ ██ ██ ██ ██████████████ - ██ ██████ ████ ██ - ██ ██████████ ██ ████████ ██████████ - ██ ██ ██ ██ ██ ████ ██████ ██ ██ ████ - ██ ██ ████████ ████ ██████ ████ ████ - ██████ ██ ██ ██ ██ ██ ██ ██████ ██ ████ - ██ ██ ████ ██ ██ ████ ██ ████████ - ██ ██ ██████ ██████ ████████ ████ ████ - ██ ████ ████ ██████ ██ ██ ████ ██ ██ ██ - ████ ████ ██ ██████ ██ ██ ██ - ██████ ██ ████████████ ██████ ██ ██ ██ ████ - ██ ████ ██ ████ ██████████████ ██ ██ - ██ ██ ████ ██ ████ ████ ██ ████ - ██ ██████ ██████ ██ ██████████ ██ ██ - ██ ████ ██████ ████ ██████ ██████████████ - ██ ██ ██ ██ ██ ██ ██ ██ - ██████████████ ██ ██████████ ██████ ██ ██ ██ - ██ ██ ████ ██ ██ ████ ████ ████ - ██ ██████ ██ ██ ██ ████ ██ ██████████ ████ - ██ ██████ ██ ██ ████ ██ ██ ██ ████ - ██ ██████ ██ ██ ██ ████ ████ ██ ████████ ██ - ██ ██ ██ ██ ██████ ████ ██ ██ - ██████████████ ██ ██ ██ ██ ██ ██ ██ ``` ## Docker container