updates based on job's comments
This commit is contained in:
parent
495a48add1
commit
86aa8e1de0
5 changed files with 43 additions and 43 deletions
4
FAQ.md
4
FAQ.md
|
@ -81,6 +81,6 @@ Note: the lbry api can only be used while either the app or lbrynet-daemon comma
|
|||
if not status['is_running']:
|
||||
print status
|
||||
else:
|
||||
for func in api.help():
|
||||
print "%s:\n%s" % (func, api.help({'function': func}))
|
||||
for cmd in api.commands():
|
||||
print "%s:\n%s" % (cmd, api.help({'command': cmd}))
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ status = api.status()
|
|||
if not status['is_running']:
|
||||
print status
|
||||
else:
|
||||
for func in api.help():
|
||||
print "%s:\n%s" % (func, api.help({'function': func}))
|
||||
for cmd in api.commands():
|
||||
print "%s:\n%s" % (cmd, api.help({'command': cmd}))
|
||||
```
|
||||
|
||||
If you've installed lbrynet, it comes with a file sharing application, called `lbrynet-daemon`, which breaks
|
||||
|
|
|
@ -1336,27 +1336,20 @@ class Daemon(AuthJSONRPCServer):
|
|||
|
||||
def jsonrpc_help(self, p=None):
|
||||
"""
|
||||
Function to retrieve docstring for API function
|
||||
Return a useful message for an API command
|
||||
|
||||
Args:
|
||||
'function': optional, function to retrieve documentation for
|
||||
'callable_during_startup': optional, returns functions that are callable during startup
|
||||
'command': optional, command to retrieve documentation for
|
||||
Returns:
|
||||
if given a function, returns given documentation
|
||||
if given callable_during_startup flag, returns list of
|
||||
functions callable during the startup sequence
|
||||
if no params are given, returns the list of callable functions
|
||||
if given a command, returns documentation about that command
|
||||
otherwise returns general help message
|
||||
"""
|
||||
|
||||
if not p:
|
||||
return self._render_response(", ".join(sorted(self.callable_methods.keys())))
|
||||
elif 'callable_during_startup' in p:
|
||||
return self._render_response(", ".join(sorted(self.allowed_during_startup)))
|
||||
elif 'function' in p:
|
||||
fn = self.callable_methods.get(p['function'])
|
||||
if p and 'command' in p:
|
||||
fn = self.callable_methods.get(p['command'])
|
||||
if fn is None:
|
||||
return self._render_response(
|
||||
"No help available for '" + p['function'] + "'. It is not a valid function."
|
||||
"No help available for '" + p['command'] + "'. It is not a valid command."
|
||||
)
|
||||
return self._render_response(textwrap.dedent(fn.__doc__))
|
||||
else:
|
||||
|
|
|
@ -15,23 +15,10 @@ def main():
|
|||
parser = argparse.ArgumentParser(add_help=False)
|
||||
_, arguments = parser.parse_known_args()
|
||||
|
||||
if len(arguments) < 1:
|
||||
print_help()
|
||||
return 1
|
||||
|
||||
method = arguments[0]
|
||||
try:
|
||||
params = parse_params(arguments[1:])
|
||||
except InvalidParameters as e:
|
||||
print_error(e.message)
|
||||
return 1
|
||||
|
||||
conf.initialize_settings()
|
||||
conf.update_settings_from_file()
|
||||
api = LBRYAPIClient.get_client()
|
||||
|
||||
# TODO: check if port is bound. Error if its not
|
||||
|
||||
try:
|
||||
status = api.status()
|
||||
except URLError as err:
|
||||
|
@ -55,15 +42,32 @@ def main():
|
|||
print " Status: " + message
|
||||
return 1
|
||||
|
||||
if len(arguments) < 1:
|
||||
print_help(api)
|
||||
return 1
|
||||
|
||||
method = arguments[0]
|
||||
try:
|
||||
params = parse_params(arguments[1:])
|
||||
except InvalidParameters as e:
|
||||
print_error(e.message)
|
||||
return 1
|
||||
|
||||
# TODO: check if port is bound. Error if its not
|
||||
|
||||
if method in ['--help', '-h', 'help']:
|
||||
if len(params) == 0:
|
||||
print_help()
|
||||
print "\nCOMMANDS\n" + wrap_list_to_term_width(api.commands(), prefix=' ')
|
||||
print_help(api)
|
||||
elif 'command' not in params:
|
||||
print_error(
|
||||
'To get help on a specific command, use `{} help command=COMMAND_NAME`'.format(
|
||||
os.path.basename(sys.argv[0]))
|
||||
)
|
||||
else:
|
||||
print api.help(params).strip()
|
||||
print api.call('help', params).strip()
|
||||
|
||||
elif method not in api.commands():
|
||||
print_error("Function '" + method + "' is not a valid function.")
|
||||
print_error("'" + method + "' is not a valid command.")
|
||||
|
||||
else:
|
||||
try:
|
||||
|
@ -79,7 +83,7 @@ def main():
|
|||
# instead of this generic message.
|
||||
# https://app.asana.com/0/158602294500137/200173944358192
|
||||
print "Something went wrong, here's the usage for %s:" % method
|
||||
print api.help({'function': method})
|
||||
print api.call('help', {'command': method})
|
||||
if hasattr(err, 'msg'):
|
||||
print "Here's the traceback for the error you encountered:"
|
||||
print err.msg
|
||||
|
@ -137,7 +141,7 @@ def print_error(message, suggest_help=True):
|
|||
print_help_suggestion()
|
||||
|
||||
|
||||
def print_help():
|
||||
def print_help(api):
|
||||
print "\n".join([
|
||||
"NAME",
|
||||
" lbrynet-cli - LBRY command line client.",
|
||||
|
@ -146,10 +150,13 @@ def print_help():
|
|||
" lbrynet-cli <command> [<args>]",
|
||||
"",
|
||||
"EXAMPLES",
|
||||
" lbrynet-cli commands # list available commands",
|
||||
" lbrynet-cli status # get daemon status",
|
||||
" lbrynet-cli resolve_name name=what # resolve a name",
|
||||
" lbrynet-cli help function=resolve_name # get help about a method",
|
||||
" lbrynet-cli commands # list available commands",
|
||||
" lbrynet-cli status # get daemon status",
|
||||
" lbrynet-cli resolve_name name=what # resolve a name",
|
||||
" lbrynet-cli help command=resolve_name # get help for a command",
|
||||
"",
|
||||
"COMMANDS",
|
||||
wrap_list_to_term_width(api.commands(), prefix=' ')
|
||||
])
|
||||
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ class AuthJSONRPCServer(AuthorizedBase):
|
|||
return version_for_return
|
||||
|
||||
def _callback_render(self, result, request, id_, version, auth_required=False):
|
||||
result_for_return = result if not isinstance(result, dict) else result['result']
|
||||
result_for_return = result
|
||||
|
||||
if version == jsonrpclib.VERSION_PRE1:
|
||||
if not isinstance(result, jsonrpclib.Fault):
|
||||
|
@ -295,4 +295,4 @@ class AuthJSONRPCServer(AuthorizedBase):
|
|||
self._render_error(err, request, id_, version)
|
||||
|
||||
def _render_response(self, result):
|
||||
return defer.succeed({'result': result, 'code': 200})
|
||||
return defer.succeed(result)
|
||||
|
|
Loading…
Reference in a new issue