forked from LBRYCommunity/lbry-sdk
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']:
|
if not status['is_running']:
|
||||||
print status
|
print status
|
||||||
else:
|
else:
|
||||||
for func in api.help():
|
for cmd in api.commands():
|
||||||
print "%s:\n%s" % (func, api.help({'function': func}))
|
print "%s:\n%s" % (cmd, api.help({'command': cmd}))
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,8 @@ status = api.status()
|
||||||
if not status['is_running']:
|
if not status['is_running']:
|
||||||
print status
|
print status
|
||||||
else:
|
else:
|
||||||
for func in api.help():
|
for cmd in api.commands():
|
||||||
print "%s:\n%s" % (func, api.help({'function': func}))
|
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
|
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):
|
def jsonrpc_help(self, p=None):
|
||||||
"""
|
"""
|
||||||
Function to retrieve docstring for API function
|
Return a useful message for an API command
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
'function': optional, function to retrieve documentation for
|
'command': optional, command to retrieve documentation for
|
||||||
'callable_during_startup': optional, returns functions that are callable during startup
|
|
||||||
Returns:
|
Returns:
|
||||||
if given a function, returns given documentation
|
if given a command, returns documentation about that command
|
||||||
if given callable_during_startup flag, returns list of
|
otherwise returns general help message
|
||||||
functions callable during the startup sequence
|
|
||||||
if no params are given, returns the list of callable functions
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not p:
|
if p and 'command' in p:
|
||||||
return self._render_response(", ".join(sorted(self.callable_methods.keys())))
|
fn = self.callable_methods.get(p['command'])
|
||||||
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 fn is None:
|
if fn is None:
|
||||||
return self._render_response(
|
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__))
|
return self._render_response(textwrap.dedent(fn.__doc__))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -15,23 +15,10 @@ def main():
|
||||||
parser = argparse.ArgumentParser(add_help=False)
|
parser = argparse.ArgumentParser(add_help=False)
|
||||||
_, arguments = parser.parse_known_args()
|
_, 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.initialize_settings()
|
||||||
conf.update_settings_from_file()
|
conf.update_settings_from_file()
|
||||||
api = LBRYAPIClient.get_client()
|
api = LBRYAPIClient.get_client()
|
||||||
|
|
||||||
# TODO: check if port is bound. Error if its not
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
status = api.status()
|
status = api.status()
|
||||||
except URLError as err:
|
except URLError as err:
|
||||||
|
@ -55,15 +42,32 @@ def main():
|
||||||
print " Status: " + message
|
print " Status: " + message
|
||||||
return 1
|
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 method in ['--help', '-h', 'help']:
|
||||||
if len(params) == 0:
|
if len(params) == 0:
|
||||||
print_help()
|
print_help(api)
|
||||||
print "\nCOMMANDS\n" + wrap_list_to_term_width(api.commands(), prefix=' ')
|
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:
|
else:
|
||||||
print api.help(params).strip()
|
print api.call('help', params).strip()
|
||||||
|
|
||||||
elif method not in api.commands():
|
elif method not in api.commands():
|
||||||
print_error("Function '" + method + "' is not a valid function.")
|
print_error("'" + method + "' is not a valid command.")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
@ -79,7 +83,7 @@ def main():
|
||||||
# instead of this generic message.
|
# instead of this generic message.
|
||||||
# https://app.asana.com/0/158602294500137/200173944358192
|
# https://app.asana.com/0/158602294500137/200173944358192
|
||||||
print "Something went wrong, here's the usage for %s:" % method
|
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'):
|
if hasattr(err, 'msg'):
|
||||||
print "Here's the traceback for the error you encountered:"
|
print "Here's the traceback for the error you encountered:"
|
||||||
print err.msg
|
print err.msg
|
||||||
|
@ -137,7 +141,7 @@ def print_error(message, suggest_help=True):
|
||||||
print_help_suggestion()
|
print_help_suggestion()
|
||||||
|
|
||||||
|
|
||||||
def print_help():
|
def print_help(api):
|
||||||
print "\n".join([
|
print "\n".join([
|
||||||
"NAME",
|
"NAME",
|
||||||
" lbrynet-cli - LBRY command line client.",
|
" lbrynet-cli - LBRY command line client.",
|
||||||
|
@ -146,10 +150,13 @@ def print_help():
|
||||||
" lbrynet-cli <command> [<args>]",
|
" lbrynet-cli <command> [<args>]",
|
||||||
"",
|
"",
|
||||||
"EXAMPLES",
|
"EXAMPLES",
|
||||||
" lbrynet-cli commands # list available commands",
|
" lbrynet-cli commands # list available commands",
|
||||||
" lbrynet-cli status # get daemon status",
|
" lbrynet-cli status # get daemon status",
|
||||||
" lbrynet-cli resolve_name name=what # resolve a name",
|
" lbrynet-cli resolve_name name=what # resolve a name",
|
||||||
" lbrynet-cli help function=resolve_name # get help about a method",
|
" 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
|
return version_for_return
|
||||||
|
|
||||||
def _callback_render(self, result, request, id_, version, auth_required=False):
|
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 version == jsonrpclib.VERSION_PRE1:
|
||||||
if not isinstance(result, jsonrpclib.Fault):
|
if not isinstance(result, jsonrpclib.Fault):
|
||||||
|
@ -295,4 +295,4 @@ class AuthJSONRPCServer(AuthorizedBase):
|
||||||
self._render_error(err, request, id_, version)
|
self._render_error(err, request, id_, version)
|
||||||
|
|
||||||
def _render_response(self, result):
|
def _render_response(self, result):
|
||||||
return defer.succeed({'result': result, 'code': 200})
|
return defer.succeed(result)
|
||||||
|
|
Loading…
Add table
Reference in a new issue