Skip to content

Commit

Permalink
zalando-stups/lizzy#119 Refactoring based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcs committed Jun 20, 2016
1 parent dbe1de4 commit 4d0b01a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
29 changes: 25 additions & 4 deletions lizzy_client/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class DefinitionParamType(click.ParamType):
def convert(self, value, param, ctx):
if isinstance(value, str):
try:
url = value if '://' in value else 'file://{}'.format(quote(os.path.abspath(value)))
url = (value if '://' in value
else 'file://{}'.format(quote(os.path.abspath(value))))

response = urlopen(url)
data = yaml.safe_load(response.read())
Expand All @@ -30,16 +31,36 @@ def convert(self, value, param, ctx):
data = value
for key in ['SenzaInfo']:
if 'SenzaInfo' not in data:
self.fail('"{}" entry is missing in YAML file "{}"'.format(key, value), param, ctx)
self.fail('"{}" entry is missing in YAML file "{}"'.format(key, value),
param, ctx)
return data


def validate_version(ctx, param, value):
if not VERSION_PATTERN.match(value):
raise click.BadParameter('Version must satisfy regular expression pattern "[a-zA-Z0-9]+"')
raise click.BadParameter('Version must satisfy regular expression '
'pattern "{}"'.format(VERSION_PATTERN.pattern))
return value


region_option = click.option('--region', envvar='AWS_DEFAULT_REGION',
dry_run_option = click.option('--dry-run',
is_flag=True,
help='No-op mode: show what would be deleted')

output_option = click.option('-o', '--output',
type=click.Choice(['text', 'json', 'tsv']),
default='text',
help='Use alternative output format')

region_option = click.option('--region',
envvar='AWS_DEFAULT_REGION',
metavar='AWS_REGION_ID',
help='AWS region ID (e.g. eu-west-1)')

remote_option = click.option('-r', '--remote',
help='URL for Agent')

watch_option = click.option('-w', '--watch',
type=click.IntRange(1, 300),
metavar='SECS',
help='Auto update the screen every X seconds')
13 changes: 5 additions & 8 deletions lizzy_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from tokens import InvalidCredentialsError
from yaml.error import YAMLError

from .arguments import DefinitionParamType, region_option, validate_version
from .arguments import (DefinitionParamType, region_option, validate_version,
dry_run_option, output_option, remote_option,
watch_option)
from .configuration import Configuration
from .lizzy import Lizzy
from .token import get_token
Expand Down Expand Up @@ -50,11 +52,6 @@
requests.packages.urllib3.disable_warnings() # Disable the security warnings

main = AliasedGroup(context_settings=dict(help_option_names=['-h', '--help']))
output_option = click.option('-o', '--output', type=click.Choice(['text', 'json', 'tsv']), default='text',
help='Use alternative output format')
remote_option = click.option('-r', '--remote', help='URL for Agent')
watch_option = click.option('-w', '--watch', type=click.IntRange(1, 300), metavar='SECS',
help='Auto update the screen every X seconds')


def connection_error(e: requests.ConnectionError, fatal=True):
Expand Down Expand Up @@ -133,7 +130,7 @@ def parse_stack_refs(stack_references: List[str]) -> List[str]:
@region_option
@click.option('--disable-rollback', is_flag=True,
help='Disable Cloud Formation rollback on failure')
@click.option('--dry-run', is_flag=True, help='No-op mode: show what would be created')
@dry_run_option
@click.option('-f', '--force', is_flag=True, help='Ignore failing validation checks')
@click.option('-t', '--tag', help='Tags to associate with the stack.', multiple=True)
@click.option('--keep-stacks', type=int, help="Number of old stacks to keep")
Expand Down Expand Up @@ -331,7 +328,7 @@ def traffic(stack_name: str, stack_version: str, percentage: int, remote: str):
@main.command()
@click.argument('stack_ref', nargs=-1)
@region_option
@click.option('--dry-run', is_flag=True, help='No-op mode: show what would be deleted')
@dry_run_option
@click.option('-f', '--force', is_flag=True, help='Allow deleting multiple stacks')
@remote_option
def delete(stack_ref: List[str],
Expand Down

0 comments on commit 4d0b01a

Please sign in to comment.