Skip to content

Commit

Permalink
Enhancement | Move tasks load and list to run command (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelofenoglio authored Jan 2, 2025
1 parent 137bf28 commit 76ca5ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
25 changes: 3 additions & 22 deletions leverage/leverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 19 additions & 2 deletions leverage/modules/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,16 +31,32 @@ 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.
"""
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:
Expand Down

0 comments on commit 76ca5ae

Please sign in to comment.