diff --git a/osxphotos/__main__.py b/osxphotos/__main__.py index d2d67cf1..167add1f 100644 --- a/osxphotos/__main__.py +++ b/osxphotos/__main__.py @@ -1149,9 +1149,12 @@ def help(ctx, topic, **kw): """ Print help; for help on commands: help . """ if topic is None: click.echo(ctx.parent.get_help()) - else: + elif topic in cli.commands: ctx.info_name = topic click.echo_via_pager(cli.commands[topic].get_help(ctx)) + else: + click.echo(f"Invalid command: {topic}", err=True) + click.echo(ctx.parent.get_help()) def print_photo_info(photos, json=False): diff --git a/tests/test_cli.py b/tests/test_cli.py index 31606e88..e877e6a0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -25,6 +25,7 @@ CLI_OUTPUT_NO_SUBCOMMAND = [ " keywords Print out keywords found in the Photos library.", " list Print list of Photos libraries found on the system.", " persons Print out persons (faces) found in the Photos library.", + " places Print out places found in the Photos library.", " query Query the Photos database using 1 or more search options; if", ] @@ -122,6 +123,43 @@ def test_osxphotos(): assert line in output +def test_osxphotos_help_1(): + # test help command no topic + import osxphotos + from osxphotos.__main__ import cli + + runner = CliRunner() + result = runner.invoke(cli, ["help"]) + output = result.output + assert result.exit_code == 0 + for line in CLI_OUTPUT_NO_SUBCOMMAND: + assert line in output + + +def test_osxphotos_help_2(): + # test help command valid topic + import osxphotos + from osxphotos.__main__ import cli + + runner = CliRunner() + result = runner.invoke(cli, ["help", "persons"]) + output = result.output + assert result.exit_code == 0 + assert "Print out persons (faces) found in the Photos library." in result.output + + +def test_osxphotos_help_3(): + # test help command invalid topic + import osxphotos + from osxphotos.__main__ import cli + + runner = CliRunner() + result = runner.invoke(cli, ["help", "foo"]) + output = result.output + assert result.exit_code == 0 + assert "Invalid command: foo" in result.output + + def test_query_uuid(): import json import os