cli: list-api method
Limit output to given method Fixes: https://pagure.io/koji/issue/2687
This commit is contained in:
parent
4fcb9815fa
commit
fdf64d0a8d
2 changed files with 47 additions and 34 deletions
|
|
@ -2459,29 +2459,34 @@ def anon_handle_latest_build(goptions, session, args):
|
|||
|
||||
def anon_handle_list_api(goptions, session, args):
|
||||
"[info] Print the list of XML-RPC APIs"
|
||||
usage = _("usage: %prog list-api [options]")
|
||||
usage = _("usage: %prog list-api [options] [method_name ...]")
|
||||
parser = OptionParser(usage=get_usage_str(usage))
|
||||
(options, args) = parser.parse_args(args)
|
||||
if len(args) != 0:
|
||||
parser.error(_("This command takes no arguments"))
|
||||
ensure_connection(session, goptions)
|
||||
for x in sorted(session._listapi(), key=lambda x: x['name']):
|
||||
if 'argdesc' in x:
|
||||
args = x['argdesc']
|
||||
elif x['args']:
|
||||
# older servers may not provide argdesc
|
||||
expanded = []
|
||||
for arg in x['args']:
|
||||
if isinstance(arg, str):
|
||||
expanded.append(arg)
|
||||
else:
|
||||
expanded.append('%s=%s' % (arg[0], arg[1]))
|
||||
args = "(%s)" % ", ".join(expanded)
|
||||
else:
|
||||
args = "()"
|
||||
print('%s%s' % (x['name'], args))
|
||||
if x['doc']:
|
||||
print(" description: %s" % x['doc'])
|
||||
if args:
|
||||
for method in args:
|
||||
help = session.system.methodHelp(method)
|
||||
if not help:
|
||||
parser.error(_("Unknown method: %s") % method)
|
||||
print(help)
|
||||
else:
|
||||
for x in sorted(session._listapi(), key=lambda x: x['name']):
|
||||
if 'argdesc' in x:
|
||||
args = x['argdesc']
|
||||
elif x['args']:
|
||||
# older servers may not provide argdesc
|
||||
expanded = []
|
||||
for arg in x['args']:
|
||||
if isinstance(arg, str):
|
||||
expanded.append(arg)
|
||||
else:
|
||||
expanded.append('%s=%s' % (arg[0], arg[1]))
|
||||
args = "(%s)" % ", ".join(expanded)
|
||||
else:
|
||||
args = "()"
|
||||
print('%s%s' % (x['name'], args))
|
||||
if x['doc']:
|
||||
print(" description: %s" % x['doc'])
|
||||
|
||||
|
||||
def anon_handle_list_tagged(goptions, session, args):
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class TestListApi(utils.CliTestCase):
|
|||
maxDiff = None
|
||||
|
||||
def setUp(self):
|
||||
self.error_format = """Usage: %s list-api [options]
|
||||
self.error_format = """Usage: %s list-api [options] [method_name]
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
%s: error: {message}
|
||||
|
|
@ -29,18 +29,7 @@ class TestListApi(utils.CliTestCase):
|
|||
session = mock.MagicMock()
|
||||
options = mock.MagicMock()
|
||||
|
||||
# Case 1. argument error
|
||||
expected = self.format_error_message(
|
||||
"This command takes no arguments")
|
||||
self.assert_system_exit(
|
||||
anon_handle_list_api,
|
||||
options,
|
||||
session,
|
||||
['arg'],
|
||||
stderr=expected,
|
||||
activate_session=None)
|
||||
|
||||
# Case 2.
|
||||
# Case 1. list all methods
|
||||
session._listapi.return_value = [
|
||||
{
|
||||
'argdesc': '(tagInfo, **kwargs)',
|
||||
|
|
@ -70,10 +59,29 @@ class TestListApi(utils.CliTestCase):
|
|||
anon_handle_list_api(options, session, [])
|
||||
self.assert_console_message(stdout, expected)
|
||||
|
||||
# Case 2. unknown method
|
||||
session.system.methodHelp.return_value = None
|
||||
expected = self.format_error_message("Unknown method: unknown method")
|
||||
self.assert_system_exit(
|
||||
anon_handle_list_api,
|
||||
options,
|
||||
session,
|
||||
['unknown method'],
|
||||
stderr=expected,
|
||||
activate_session=None)
|
||||
|
||||
# Case 3. known method
|
||||
session.system.methodHelp.return_value = "editTag2(tagInfo, **kwargs)\n" \
|
||||
" description: Edit information for an existing tag."
|
||||
anon_handle_list_api(options, session, ['editTag2'])
|
||||
expected = "editTag2(tagInfo, **kwargs)\n"
|
||||
expected += " description: Edit information for an existing tag.\n"
|
||||
self.assert_console_message(stdout, expected)
|
||||
|
||||
def test_anon_handle_list_api_help(self):
|
||||
self.assert_help(
|
||||
anon_handle_list_api,
|
||||
"""Usage: %s list-api [options]
|
||||
"""Usage: %s list-api [options] [method_name]
|
||||
(Specify the --help global option for a list of other help options)
|
||||
|
||||
Options:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue