Skip to content

Commit

Permalink
add "help" command (#854)
Browse files Browse the repository at this point in the history
fixes #787
  • Loading branch information
fsr313 committed Jun 16, 2020
1 parent b584a46 commit b682359
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/popper/commands/cmd_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import click
import os

from popper.cli import pass_context, log, PopperCLI, cmd_folder

popper_cli = PopperCLI()


@click.command("help", short_help="shows help for a given command")
@click.argument(
"subcommand",
type=click.Choice(popper_cli.list_commands(click.Context(popper_cli))),
required=False,
)
@pass_context
def cli(ctx, subcommand):
""" Display help for a given command or popper default help
"""
if subcommand:
target_command = popper_cli.get_command(ctx, subcommand)
log.info(target_command.get_help(click.Context(popper_cli)))
else:
log.info(popper_cli.get_help(click.Context(popper_cli)))
30 changes: 30 additions & 0 deletions src/test/test_cmd_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from click.testing import CliRunner
import click
from click import Context

from popper.commands import cmd_help
from .test_common import PopperTest
from popper.cli import PopperCLI, cmd_folder


class TestCommandHelp(PopperTest):
def test_help(self):
popper_cli = PopperCLI()
subcommands = popper_cli.list_commands(click.Context(popper_cli))

help_texts = []
with self.assertLogs("popper") as test:
runner = CliRunner()
for subcommand in subcommands:
result = runner.invoke(cmd_help.cli, [subcommand])
self.assertEqual(result.exit_code, 0)
target_command = popper_cli.get_command(
click.Context(popper_cli), subcommand
)
help_texts.append(target_command.get_help(click.Context(popper_cli)))

for command_output, test_output in zip(help_texts, test.output):
self.assertIn(
command_output.replace(" ", "").replace("\n", ""),
test_output.replace(" ", "").replace("\n", ""),
)

0 comments on commit b682359

Please sign in to comment.