Skip to content

Commit

Permalink
initial revision of cli.py
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Büchse <matthias.buechse@cloudandheat.com>
  • Loading branch information
mbuechse committed Jan 26, 2024
1 parent 763d480 commit 88c531c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Tests/iaas/flavor-naming/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python3
import click
import sys

from flavor_name_check import parser_v1, parser_v2


class Version:
def __init__(self, parser):
self.parser = parser


VERSIONS = {
'v1': Version(parser_v1),
'v2': Version(parser_v2),
'v3': Version(parser_v2),
}
VERSIONS['latest'] = VERSIONS['v3']


@click.group()
@click.argument('version', type=click.Choice(list(VERSIONS), case_sensitive=False))
@click.pass_context
def cli(ctx, version):
vobj = VERSIONS.get(version)
ctx.obj['version'] = vobj


@cli.result_callback()
def process_pipeline(rc, *args, **kwargs):
sys.exit(rc)


@cli.command()
@click.argument('namestr', nargs=-1)
@click.pass_context
def check(ctx, namestr):
version = ctx.obj['version']
errors = 0
for name in namestr:
try:
flavorname = version.parser(name)
except ValueError as exc:
print(f"✘ {name}: ERROR {exc}")
errors += 1
else:
if flavorname is None:
print(f" {name}: NOT an SCS flavor")
else:
print(f"✓ {name}: OK")
return errors


if __name__ == '__main__':
cli(obj={})
1 change: 1 addition & 0 deletions Tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
click
fabric
kubernetes_asyncio
PyYAML==6.0
Expand Down

0 comments on commit 88c531c

Please sign in to comment.