diff --git a/leverage/leverage.py b/leverage/leverage.py index 1cbf4ea..b5f2634 100644 --- a/leverage/leverage.py +++ b/leverage/leverage.py @@ -4,8 +4,6 @@ import click from leverage import __version__ -from leverage.tasks import load_tasks -from leverage.tasks import list_tasks as _list_tasks from leverage._internals import pass_state from leverage.modules.aws import aws @@ -14,34 +12,17 @@ @click.group(invoke_without_command=True) -@click.option( - "--filename", - "-f", - default="build.py", - show_default=True, - help="Name of the build file containing the tasks definitions.", -) -@click.option("--list-tasks", "-l", is_flag=True, help="List available tasks to run.") @click.option("-v", "--verbose", is_flag=True, help="Increase output verbosity.") @click.version_option(version=__version__) @pass_state @click.pass_context -def leverage(context, state, filename, list_tasks, verbose): +def leverage(context, state, verbose): """Leverage Reference Architecture projects command-line tool.""" # --verbose | -v state.verbosity = verbose - - # Load build file as a module - state.module = load_tasks(build_script_filename=filename) - if context.invoked_subcommand is None: - # --list-tasks|-l - if list_tasks: - _list_tasks(state.module) - - else: - # leverage called with no subcommand - click.echo(context.get_help()) + # leverage called with no subcommand + click.echo(context.get_help()) # Add modules to leverage diff --git a/leverage/modules/run.py b/leverage/modules/run.py index b4781ef..187263f 100644 --- a/leverage/modules/run.py +++ b/leverage/modules/run.py @@ -7,7 +7,8 @@ from click.exceptions import Exit from leverage import logger -from leverage.tasks import list_tasks +from leverage.tasks import load_tasks +from leverage.tasks import list_tasks as _list_tasks from leverage.logger import get_tasks_logger from leverage._parsing import parse_task_args from leverage._parsing import InvalidArgumentOrderError @@ -30,9 +31,17 @@ class TaskNotFoundError(RuntimeError): @click.command() +@click.option( + "--filename", + "-f", + default="build.py", + show_default=True, + help="Name of the build file containing the tasks definitions.", +) +@click.option("--list-tasks", "-l", is_flag=True, help="List available tasks to run.") @click.argument("tasks", nargs=-1) @pass_state -def run(state, tasks): +def run(state, filename, list_tasks, tasks): """Perform specified task(s) and all of its dependencies. When no task is given, the default (__DEFAULT__) task is run, if no default task has been defined, all available tasks are listed. @@ -40,6 +49,14 @@ def run(state, tasks): global _logger _logger = get_tasks_logger() + # Load build file as a module + state.module = load_tasks(build_script_filename=filename) + + if list_tasks: + # --list-tasks|-l + _list_tasks(state.module) + return + if tasks: # Run the given tasks try: diff --git a/pyproject.toml b/pyproject.toml index b19e3fc..c64d34e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,8 +39,8 @@ boto3 = "1.33.2" configupdater = "3.2" docutils = "0.17.1" rich = "10.4.0" - requests = "2.31" + [tool.poetry.group.dev.dependencies] pylint = "2.8.3" pytest = "6.2.4"