mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-09-02 18:25:14 +00:00
add help for when things go wrong
This commit is contained in:
parent
34b1259dc6
commit
9277c3c674
1 changed files with 27 additions and 6 deletions
|
@ -4,6 +4,13 @@ import json
|
||||||
from lbrynet.conf import API_CONNECTION_STRING, LOG_FILE_NAME
|
from lbrynet.conf import API_CONNECTION_STRING, LOG_FILE_NAME
|
||||||
from jsonrpc.proxy import JSONRPCProxy
|
from jsonrpc.proxy import JSONRPCProxy
|
||||||
|
|
||||||
|
help_msg = "Useage: lbrynet-cli method json-args\n" \
|
||||||
|
+ "Examples: " \
|
||||||
|
+ "lbrynet-cli resolve_name '{\"name\": \"what\"}'\n" \
|
||||||
|
+ "lbrynet-cli get_balance\n" \
|
||||||
|
+ "lbrynet-cli help '{\"function\": \"resolve_name\"}'\n" \
|
||||||
|
+ "\n******lbrynet-cli functions******\n"
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
api = JSONRPCProxy.from_url(API_CONNECTION_STRING)
|
api = JSONRPCProxy.from_url(API_CONNECTION_STRING)
|
||||||
|
@ -16,6 +23,15 @@ def main():
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
meth = args[0]
|
meth = args[0]
|
||||||
|
|
||||||
|
msg = help_msg
|
||||||
|
for f in api.help():
|
||||||
|
msg += f + "\n"
|
||||||
|
|
||||||
|
if meth in ['--help', '-h', 'help']:
|
||||||
|
print msg
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
if isinstance(args[1], dict):
|
if isinstance(args[1], dict):
|
||||||
params = args[1]
|
params = args[1]
|
||||||
|
@ -25,13 +41,18 @@ def main():
|
||||||
params = None
|
params = None
|
||||||
|
|
||||||
if meth in api.help():
|
if meth in api.help():
|
||||||
if params:
|
try:
|
||||||
r = api.call(meth, params)
|
if params:
|
||||||
else:
|
r = api.call(meth, params)
|
||||||
r = api.call(meth)
|
else:
|
||||||
print r
|
r = api.call(meth)
|
||||||
|
print r
|
||||||
|
except:
|
||||||
|
print "Something went wrong, here's the usage for %s:" % meth
|
||||||
|
print api.help({'function': meth})
|
||||||
else:
|
else:
|
||||||
print "Unrecognized function"
|
print "Unknown function"
|
||||||
|
print msg
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Reference in a new issue