More click code

This commit is contained in:
David Boreham 2022-08-24 12:29:51 -06:00
parent c9d42886d5
commit 2fadafbd87
2 changed files with 26 additions and 21 deletions

View File

@ -41,23 +41,21 @@ def is_git_repo(path):
except git.exc.InvalidGitRepositoryError:
return False
parser = argparse.ArgumentParser(
description="git clone the set of repositories required to build the complete system from source",
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")
parser.add_argument("--pull", action="store_true", help="pull from remote in already existing repositories")
args = parser.parse_args()
# TODO: find a place for this in the context of click
#parser = argparse.ArgumentParser(
# epilog="Config provided either in .env or settings.ini or env vars: CERC_REPO_BASE_DIR (defaults to ~/cerc)"
# )
@click.command()
def command():
@click.option('--check-only', default=False)
@click.option('--pull', default=False)
@click.pass_context
def command(ctx, check_only, pull):
'''git clone the set of repositories required to build the complete system from source'''
verbose = args.verbose
quiet = args.quiet
quiet = ctx.obj.quiet
verbose = ctx.obj.verbose
dry_run = ctx.obj.verbose
dev_root_path = os.path.expanduser(config("DEV_ROOT", default="~/cerc"))
@ -89,10 +87,10 @@ def command():
print(f'Error: {full_filesystem_repo_path} does not contain a valid git repository')
sys.exit(1)
else:
if args.pull:
if pull:
if verbose:
print(f'Running git pull for {full_filesystem_repo_path}')
if not args.check_only:
if not check_only:
repo = git.Repo(full_filesystem_repo_path)
origin = repo.remotes.origin
origin.pull(progress = None if quiet else GitProgress())
@ -102,7 +100,7 @@ def command():
# Clone
if verbose:
print(f'Running git clone for {full_github_repo_path} into {full_filesystem_repo_path}')
if not args.check_only:
if not dry_run:
git.Repo.clone_from(full_github_repo_path, full_filesystem_repo_path,
progress = None if quiet else GitProgress())
else:

15
cli.py
View File

@ -21,14 +21,21 @@ from app import deploy_system
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
class Options(object):
def __init__(self, quiet, verbose, dry_run):
self.quiet = quiet
self.verbose = verbose
self.dry_run = dry_run
@click.group(context_settings=CONTEXT_SETTINGS)
@click.option('--quiet', default=False)
@click.option('--verbose', default=False)
@click.option('--dry-run', default=False)
def cli():
"""Example script."""
print("Yo!")
click.echo('Hello World!')
# See: https://click.palletsprojects.com/en/8.1.x/complex/#building-a-git-clone
@click.pass_context
def cli(ctx, quiet, verbose, dry_run):
"""Laconic Stack Orchestrator"""
ctx.obj = Options(quiet, verbose, dry_run)
cli.add_command(setup_repositories.command,"setup-repositories")
cli.add_command(build_containers.command,"build-containers")