More click refactoring

This commit is contained in:
David Boreham 2022-08-24 12:36:58 -06:00
parent 2fadafbd87
commit 397866f18b
10 changed files with 25 additions and 17 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -27,25 +27,28 @@ from decouple import config
import subprocess import subprocess
import click import click
parser = argparse.ArgumentParser( #parser = argparse.ArgumentParser(
description="build the set of containers required for a complete stack", # 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("--verbose", action="store_true", help="increase output verbosity")
parser.add_argument("--quiet", action="store_true", help="don\'t print informational output") #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("--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") #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() #args = parser.parse_args()
@click.command() @click.command()
def command(): @click.pass_context
verbose = args.verbose def command(ctx):
quiet = args.quiet
quiet = ctx.obj.quiet
verbose = ctx.obj.verbose
dry_run = ctx.obj.verbose
dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc")) dev_root_path = os.path.expanduser(config("CERC_REPO_BASE_DIR", default="~/cerc"))
if not args.quiet: if not quiet:
print(f'Dev Root is: {dev_root_path}') print(f'Dev Root is: {dev_root_path}')
if not os.path.isdir(dev_root_path): if not os.path.isdir(dev_root_path):
@ -66,7 +69,7 @@ def command():
if not os.path.exists(build_script_filename): if not os.path.exists(build_script_filename):
print(f"Error, script: {build_script_filename} doesn't exist") print(f"Error, script: {build_script_filename} doesn't exist")
sys.exit(1) sys.exit(1)
if not args.dry_run: if not dry_run:
# We need to export CERC_REPO_BASE_DIR # We need to export CERC_REPO_BASE_DIR
build_result = subprocess.run(build_script_filename, shell=True, env={'CERC_REPO_BASE_DIR':dev_root_path}) build_result = subprocess.run(build_script_filename, shell=True, env={'CERC_REPO_BASE_DIR':dev_root_path})
# TODO: check result in build_result.returncode # TODO: check result in build_result.returncode

View File

@ -51,7 +51,12 @@ def include_exclude_check(s, args):
#print("Yo2!") #print("Yo2!")
@click.command() @click.command()
def command(): @click.pass_context
def command(ctx):
quiet = ctx.obj.quiet
verbose = ctx.obj.verbose
dry_run = ctx.obj.verbose
with open("cluster-list.txt") as cluster_list_file: with open("cluster-list.txt") as cluster_list_file:
clusters = cluster_list_file.read().splitlines() clusters = cluster_list_file.read().splitlines()
@ -76,8 +81,8 @@ def command():
# 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 = args.command[0] command = "hack"
if not args.dry_run: if not dry_run:
if command == "up": if command == "up":
if verbose: if verbose:
print("Running compose up") print("Running compose up")