Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Need guidance to continue) Make help message more useful byusing config. #4072

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/molecule/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,25 @@ def click_command_ex() -> Callable[[Callable[..., Any]], click.Command]:
)


def click_expand_help(f) -> Callable[[Callable[..., Any]], click.Command]:
"""This decorator add sequence to help message."""
# Ask: How to get the scenario name (if help is called) or which scenario name to choose ?
s = molecule.scenarios.Scenarios(get_configs({}, {}), None)
for scenario in s.all:
if scenario.name == "default":
try:
default_sequence = getattr(scenario, f.__name__ + "_sequence")
except AttributeError:
raise RuntimeError(
f"Unable to find property {f.__name__}_sequence in class {type(scenario)}.\n"
"You might consider adding it with default action for this command.",
)
f.__doc__ += (
" (" + ", ".join(default_sequence) + ")."
) # print("self.all[0]:", type(next(iter(s.all))))
return f


def result_callback(*args, **kwargs):
"""Click natural exit callback."""
# We want to be used we run out custom exit code, regardless if run was
Expand Down
5 changes: 2 additions & 3 deletions src/molecule/command/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ def execute(self, action_args=None):
default=MOLECULE_PARALLEL,
help="Enable or disable parallel mode. Default is disabled.",
)
@base.click_expand_help
def check(ctx, scenario_name, parallel): # pragma: no cover
"""Use the provisioner to perform a Dry-Run (destroy, dependency, create, \
prepare, converge).
"""
"""Use the provisioner to perform a Dry-Run"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {"parallel": parallel, "subcommand": subcommand}
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ def execute(self, action_args=None):
default=base.MOLECULE_DEFAULT_SCENARIO_NAME,
help=f"Name of the scenario to target. ({base.MOLECULE_DEFAULT_SCENARIO_NAME})",
)
@base.click_expand_help
def cleanup(ctx, scenario_name="default"): # pragma: no cover
"""Use the provisioner to cleanup any changes made to external systems during \
the stages of testing.
the stages of testing
"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/converge.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def execute(self, action_args: list[str] | None = None) -> None:
help=f"Name of the scenario to target. ({base.MOLECULE_DEFAULT_SCENARIO_NAME})",
)
@click.argument("ansible_args", nargs=-1, type=click.UNPROCESSED)
@base.click_expand_help
def converge(ctx, scenario_name, ansible_args): # pragma: no cover
"""Use the provisioner to configure instances (dependency, create, prepare converge)."""
"""Use the provisioner to configure instances"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {"subcommand": subcommand}
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ def execute(self, action_args=None):
type=click.Choice([str(s) for s in drivers()]),
help=f"Name of driver to use. ({DEFAULT_DRIVER})",
)
@base.click_expand_help
def create(ctx, scenario_name, driver_name): # pragma: no cover
"""Use the provisioner to start the instances."""
"""Use the provisioner to start the instances"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {"subcommand": subcommand, "driver_name": driver_name}
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def execute(self, action_args=None):
default=base.MOLECULE_DEFAULT_SCENARIO_NAME,
help=f"Name of the scenario to target. ({base.MOLECULE_DEFAULT_SCENARIO_NAME})",
)
@base.click_expand_help
def dependency(ctx, scenario_name): # pragma: no cover
"""Manage the role's dependencies."""
"""Manage the role's dependencies"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {"subcommand": subcommand}
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def execute(self, action_args=None):
default=False,
help="Enable or disable parallel mode. Default is disabled.",
)
@base.click_expand_help
def destroy(ctx, scenario_name, driver_name, __all, parallel): # pragma: no cover
"""Use the provisioner to destroy the instances."""
"""Use the provisioner to destroy the instances"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {
Expand Down
4 changes: 2 additions & 2 deletions src/molecule/command/idempotence.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def _non_idempotent_tasks(self, output):
help=f"Name of the scenario to target. ({base.MOLECULE_DEFAULT_SCENARIO_NAME})",
)
@click.argument("ansible_args", nargs=-1, type=click.UNPROCESSED)
@base.click_expand_help
def idempotence(ctx, scenario_name, ansible_args): # pragma: no cover
"""Use the provisioner to configure the instances and parse the output to \
determine idempotence.
"""
determine idempotence"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {"subcommand": subcommand}
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ def execute(self, action_args=None):
default=False,
help="Enable or disable force mode. Default is disabled.",
)
@base.click_expand_help
def prepare(ctx, scenario_name, driver_name, force): # pragma: no cover
"""Use the provisioner to prepare the instances into a particular starting state."""
"""Use the provisioner to prepare the instances into a particular starting state"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/side_effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def execute(self, action_args=None):
default=base.MOLECULE_DEFAULT_SCENARIO_NAME,
help=f"Name of the scenario to target. ({base.MOLECULE_DEFAULT_SCENARIO_NAME})",
)
@base.click_expand_help
def side_effect(ctx, scenario_name): # pragma: no cover
"""Use the provisioner to perform side-effects to the instances."""
"""Use the provisioner to perform side-effects to the instances"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {"subcommand": subcommand}
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def execute(self, action_args=None):
default=base.MOLECULE_DEFAULT_SCENARIO_NAME,
help=f"Name of the scenario to target. ({base.MOLECULE_DEFAULT_SCENARIO_NAME})",
)
@base.click_expand_help
def syntax(ctx, scenario_name): # pragma: no cover
"""Use the provisioner to syntax check the role."""
"""Use the provisioner to syntax check the role"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {"subcommand": subcommand}
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def execute(self, action_args=None):
help="Enable or disable parallel mode. Default is disabled.",
)
@click.argument("ansible_args", nargs=-1, type=click.UNPROCESSED)
@base.click_expand_help
def test(
ctx,
scenario_name,
Expand All @@ -93,7 +94,7 @@ def test(
ansible_args,
platform_name,
): # pragma: no cover
"""Test (dependency, cleanup, destroy, syntax, create, prepare, converge, idempotence, side_effect, verify, cleanup, destroy)."""
"""Test"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {
Expand Down
3 changes: 2 additions & 1 deletion src/molecule/command/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def execute(self, action_args=None):
default=base.MOLECULE_DEFAULT_SCENARIO_NAME,
help=f"Name of the scenario to target. ({base.MOLECULE_DEFAULT_SCENARIO_NAME})",
)
@base.click_expand_help
def verify(ctx, scenario_name="default"): # pragma: no cover
"""Run automated tests against instances."""
"""Run automated tests against instances"""
args = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__)
command_args = {"subcommand": subcommand}
Expand Down
Loading