Fixed CLI help for invalid topic, closes #76
This commit is contained in:
@@ -1149,9 +1149,12 @@ def help(ctx, topic, **kw):
|
|||||||
""" Print help; for help on commands: help <command>. """
|
""" Print help; for help on commands: help <command>. """
|
||||||
if topic is None:
|
if topic is None:
|
||||||
click.echo(ctx.parent.get_help())
|
click.echo(ctx.parent.get_help())
|
||||||
else:
|
elif topic in cli.commands:
|
||||||
ctx.info_name = topic
|
ctx.info_name = topic
|
||||||
click.echo_via_pager(cli.commands[topic].get_help(ctx))
|
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):
|
def print_photo_info(photos, json=False):
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ CLI_OUTPUT_NO_SUBCOMMAND = [
|
|||||||
" keywords Print out keywords found in the Photos library.",
|
" keywords Print out keywords found in the Photos library.",
|
||||||
" list Print list of Photos libraries found on the system.",
|
" list Print list of Photos libraries found on the system.",
|
||||||
" persons Print out persons (faces) found in the Photos library.",
|
" 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",
|
" query Query the Photos database using 1 or more search options; if",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -122,6 +123,43 @@ def test_osxphotos():
|
|||||||
assert line in output
|
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():
|
def test_query_uuid():
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|||||||
Reference in New Issue
Block a user