diff --git a/FAQ.md b/FAQ.md index 71c8ca737..d3c631d26 100644 --- a/FAQ.md +++ b/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})) diff --git a/README.md b/README.md index 736d3ae20..fa1b1cb7e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lbrynet/lbrynet_daemon/Daemon.py b/lbrynet/lbrynet_daemon/Daemon.py index ea8777c33..0aabf5046 100644 --- a/lbrynet/lbrynet_daemon/Daemon.py +++ b/lbrynet/lbrynet_daemon/Daemon.py @@ -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: diff --git a/lbrynet/lbrynet_daemon/DaemonCLI.py b/lbrynet/lbrynet_daemon/DaemonCLI.py index a153637c0..e3339ca32 100644 --- a/lbrynet/lbrynet_daemon/DaemonCLI.py +++ b/lbrynet/lbrynet_daemon/DaemonCLI.py @@ -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 []", "", "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=' ') ]) diff --git a/lbrynet/lbrynet_daemon/auth/server.py b/lbrynet/lbrynet_daemon/auth/server.py index f7513a458..d96a25a45 100644 --- a/lbrynet/lbrynet_daemon/auth/server.py +++ b/lbrynet/lbrynet_daemon/auth/server.py @@ -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)