Skip to content

Commit

Permalink
feat: add version command (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
shpaker authored Nov 13, 2022
1 parent da2be38 commit 005464a
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 58 deletions.
25 changes: 7 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,24 @@ 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/*/})"
echo "##[set-output name=minor_ver;]$(TMP_VAR=${GITHUB_REF#refs/*/}; echo ${TMP_VAR%.*})"
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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 3 additions & 0 deletions makeqr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
QRWiFiModel,
)
from makeqr.typing import QRDataModelType
from makeqr.version import VERSION

__version__ = VERSION
__all__ = (
"MakeQR",
"QRDataModelType",
Expand All @@ -20,4 +22,5 @@
"QRTelModel",
"QRTextModel",
"QRWiFiModel",
"VERSION",
)
40 changes: 36 additions & 4 deletions makeqr/cli_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pydantic import BaseModel, ValidationError

from makeqr import (
VERSION,
MakeQR,
QRDataModelType,
QRGeoModel,
Expand All @@ -28,6 +29,15 @@
QRTextModel,
QRWiFiModel,
)
_CAPTION = (
" __ __ _______ ___ _ _______ _______ ______\n"
"| |_| || _ || | | || || || _ |\n"
"| || |_| || |_| || ___|| _ || | ||\n"
"| || || _|| |___ | | | || |_||_\n"
"| || || |_ | ___|| |_| || __ |\n"
"| ||_|| || _ || _ || |___ | | | | | |\n"
"|_| |_||__| |__||___| |_||_______||____||_||___| |_|"
)


class FieldExtraClickOptionsModel(BaseModel, arbitrary_types_allowed=True):
Expand All @@ -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))
Expand Down Expand Up @@ -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(
Expand All @@ -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"],
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions makeqr/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "0.1.0"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "makeqr"
name = "MakeQR"
version = "0.1.0"
description = "Generate QR cards for any occasion"
authors = ["Aleksandr Shpak <[email protected]>"]
Expand Down
79 changes: 45 additions & 34 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ makeqr --help

or

```
```bash
makeqr wifi --help
```

Expand All @@ -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
Expand Down

0 comments on commit 005464a

Please sign in to comment.