1
0

Finish converstion to click

This commit is contained in:
David Boreham 2022-08-24 12:53:51 -06:00
parent ca5cf55485
commit b0fc8da64d
2 changed files with 16 additions and 40 deletions

View File

@ -27,20 +27,13 @@ from decouple import config
import subprocess import subprocess
import click import click
#parser = argparse.ArgumentParser( # TODO: find a place for this
# description="build the set of containers required for a complete stack",
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)" # epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
# )
#parser.add_argument("--verbose", action="store_true", help="increase output verbosity")
#parser.add_argument("--quiet", action="store_true", help="don\'t print informational output")
#parser.add_argument("--check-only", action="store_true", help="looks at what\'s already there and checks if it looks good")
#parser.add_argument("--dry-run", action="store_true", help="don\'t do anything, just print the commands that would be executed")
#args = parser.parse_args()
@click.command() @click.command()
@click.pass_context @click.pass_context
def command(ctx): def command(ctx):
'''build the set of containers required for a complete stack'''
quiet = ctx.obj.quiet quiet = ctx.obj.quiet
verbose = ctx.obj.verbose verbose = ctx.obj.verbose
@ -77,6 +70,3 @@ def command(ctx):
for container in containers: for container in containers:
process_container(container) process_container(container)

View File

@ -21,38 +21,25 @@ from decouple import config
from python_on_whales import DockerClient from python_on_whales import DockerClient
import click import click
def include_exclude_check(s, args): def include_exclude_check(s, include, exclude):
if args.include == None and args.exclude == None: if include == None and exclude == None:
return True return True
if args.include != None: if include != None:
include_list = args.include.split(",") include_list = include.split(",")
return s in include_list return s in include_list
if args.exclude != None: if exclude != None:
exclude_list = args.exclude.split(",") exclude_list = exclude.split(",")
return s not in exclude_list return s not in exclude_list
#parser = argparse.ArgumentParser(
# description="deploy the complete stack"
# )
#parser.add_argument("command", type=str, nargs=1, choices=['up', 'down', 'ps'], help="command: up|down|ps")
#parser.add_argument("--verbose", action="store_true", help="increase output verbosity")
#parser.add_argument("--quiet", action="store_true", help="don\'t print informational output")
#parser.add_argument("--check-only", action="store_true", help="looks at what\'s already there and checks if it looks good")
#parser.add_argument("--dry-run", action="store_true", help="don\'t do anything, just print the commands that would be executed")
#group = parser.add_mutually_exclusive_group()
#group.add_argument("--exclude", type=str, help="don\'t start these components")
#group.add_argument("--include", type=str, help="only start these components")
#args = parser.parse_args()
#verbose = args.verbose
#quiet = args.quiet
#print("Yo2!")
@click.command() @click.command()
@click.option('--include', help="only start these components")
@click.option('--exclude', help="don\'t start these components")
@click.argument('command' help="command: up|down|ps")
@click.pass_context @click.pass_context
def command(ctx): def command(ctx, include, exclude, command):
'''deploy a stack'''
# TODO: implement option exclusion and command value constraint lost with the move from argparse to click
quiet = ctx.obj.quiet quiet = ctx.obj.quiet
verbose = ctx.obj.verbose verbose = ctx.obj.verbose
@ -68,7 +55,7 @@ def command(ctx):
compose_files = [] compose_files = []
for cluster in clusters: for cluster in clusters:
if include_exclude_check(cluster, args): if include_exclude_check(cluster, include, exclude):
compose_file_name = os.path.join("compose", f"docker-compose-{cluster}.yml") compose_file_name = os.path.join("compose", f"docker-compose-{cluster}.yml")
compose_files.append(compose_file_name) compose_files.append(compose_file_name)
else: else:
@ -81,7 +68,6 @@ def command(ctx):
# See: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/ # See: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/
docker = DockerClient(compose_files=compose_files) docker = DockerClient(compose_files=compose_files)
command = "hack"
if not dry_run: if not dry_run:
if command == "up": if command == "up":
if verbose: if verbose: