stack-orchestrator/cli.py

61 lines
2.4 KiB
Python
Raw Permalink Normal View History

2022-08-23 17:32:55 +00:00
# Copyright © 2022 Cerc
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
2022-08-24 03:27:42 +00:00
import click
2022-08-24 17:57:35 +00:00
from app import setup_repositories
from app import build_containers
2023-01-04 23:16:40 +00:00
from app import build_npms
2022-08-24 17:57:35 +00:00
from app import deploy_system
2023-01-10 21:09:38 +00:00
from app import version
2022-08-24 03:27:42 +00:00
2022-08-24 17:57:35 +00:00
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
2022-08-24 03:27:42 +00:00
2022-10-04 01:37:18 +00:00
# TODO: this seems kind of weird and heavy on boilerplate -- check it is
# the best Python can do for us.
2022-08-24 18:29:51 +00:00
class Options(object):
def __init__(self, stack, quiet, verbose, dry_run, local_stack, debug, continue_on_error):
self.stack = stack
2022-08-24 18:29:51 +00:00
self.quiet = quiet
self.verbose = verbose
self.dry_run = dry_run
2022-09-29 19:05:28 +00:00
self.local_stack = local_stack
self.debug = debug
self.continue_on_error = continue_on_error
2022-08-24 18:29:51 +00:00
2022-10-06 12:51:55 +00:00
2022-08-24 17:57:35 +00:00
@click.group(context_settings=CONTEXT_SETTINGS)
@click.option('--stack', help="specify a stack to build/deploy")
2022-08-24 19:01:35 +00:00
@click.option('--quiet', is_flag=True, default=False)
@click.option('--verbose', is_flag=True, default=False)
@click.option('--dry-run', is_flag=True, default=False)
@click.option('--local-stack', is_flag=True, default=False)
@click.option('--debug', is_flag=True, default=False)
@click.option('--continue-on-error', is_flag=True, default=False)
2022-08-24 18:29:51 +00:00
# See: https://click.palletsprojects.com/en/8.1.x/complex/#building-a-git-clone
@click.pass_context
def cli(ctx, stack, quiet, verbose, dry_run, local_stack, debug, continue_on_error):
2022-08-24 18:29:51 +00:00
"""Laconic Stack Orchestrator"""
ctx.obj = Options(stack, quiet, verbose, dry_run, local_stack, debug, continue_on_error)
2022-08-24 17:57:35 +00:00
2022-10-04 01:37:18 +00:00
cli.add_command(setup_repositories.command, "setup-repositories")
cli.add_command(build_containers.command, "build-containers")
2023-01-04 23:16:40 +00:00
cli.add_command(build_npms.command, "build-npms")
cli.add_command(deploy_system.command, "deploy") # deploy is an alias for deploy-system
2022-10-04 01:37:18 +00:00
cli.add_command(deploy_system.command, "deploy-system")
2023-01-10 21:09:38 +00:00
cli.add_command(version.command, "version")