From 7c57a7c38eedc48f3f2e0e1b56e744e96d19607f Mon Sep 17 00:00:00 2001 From: "Moritz.Koenemann" Date: Mon, 9 Mar 2020 14:11:02 +0100 Subject: [PATCH 1/3] Added failing test for usage message. --- tests/test_cli.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 1e828b94..8837d272 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -88,6 +88,18 @@ def get_start_date(watson, output): return watson.frames[frame_id].start.format('YYYY-MM-DD HH:mm:ss') +# watson help + +@pytest.mark.parametrize('cmd_name', ['add', 'start', 'stop']) +def test_show_command_help(runner, watson, cmd_name): + result = runner.invoke( + cli.help, + [cmd_name], + obj=watson) + assert result.exit_code == 0 + assert result.output.startswith('Usage: ' + cmd_name) + + # watson add @pytest.mark.parametrize('test_dt,expected', VALID_DATES_DATA) From c468506497ca22ff92455f94ca2f9dd8c0ea3fde Mon Sep 17 00:00:00 2001 From: "Moritz.Koenemann" Date: Mon, 9 Mar 2020 14:34:01 +0100 Subject: [PATCH 2/3] This fixes the help message shown by 'watson help '. The context passed by click is that of the 'help' command, which would have printed 'Usage: watson help [OPTIONS]...' instead of e.g. 'Usage: watson start [OPTIONS]...' --- watson/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/watson/cli.py b/watson/cli.py index 1646dc1a..fd6db842 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -158,7 +158,10 @@ def help(ctx, command): if not cmd: raise click.ClickException(u"No such command: {}".format(command)) - click.echo(cmd.get_help(ctx)) + # the passed context is that of the 'help' command, which would + # show up in the Usage: ... - message. Create the proper context: + cmd_context = click.Context(cmd, parent=ctx.parent, info_name=cmd.name) + click.echo(cmd.get_help(cmd_context)) def _start(watson, project, tags, restart=False, gap=True): From f61ee473e02cc4d2f5ae4860c4e66bf28ab93c8f Mon Sep 17 00:00:00 2001 From: "Moritz.Koenemann" Date: Mon, 9 Mar 2020 14:46:35 +0100 Subject: [PATCH 3/3] Satisfy PEP-8. --- tests/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 8837d272..e95c6559 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -95,7 +95,7 @@ def test_show_command_help(runner, watson, cmd_name): result = runner.invoke( cli.help, [cmd_name], - obj=watson) + obj=watson) assert result.exit_code == 0 assert result.output.startswith('Usage: ' + cmd_name)