-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #787
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", ""), | ||
) |