Skip to content

Commit

Permalink
Move tasks load and list to run command
Browse files Browse the repository at this point in the history
  • Loading branch information
angelofenoglio committed Oct 17, 2024
1 parent 2992536 commit 8314829
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8314829

Please sign in to comment.