Browse Source

remove unused argparse json options, use configuration instead of args for json output

Signed-off-by: R4SAS <r4sas@i2pmail.org>
master
R4SAS 4 months ago
parent
commit
c22c0f06ae
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 10
      pbincli/actions.py
  2. 4
      pbincli/cli.py

10
pbincli/actions.py

@ -21,14 +21,14 @@ def send(args, api_client, settings=None):
if args.text: if args.text:
text = args.text text = args.text
elif args.stdin: elif args.stdin:
if not args.json: print("Reading text from stdin…") if not settings['json']: print("Reading text from stdin…")
text = args.stdin.read() text = args.stdin.read()
elif not args.file: elif not args.file:
PBinCLIError("Nothing to send!") PBinCLIError("Nothing to send!")
else: else:
text = "" text = ""
if not args.json: print("Preparing paste…") if not settings['json']: print("Preparing paste…")
paste = Paste(args.debug) paste = Paste(args.debug)
if args.verbose: print("Used server: {}".format(api_client.getServer())) if args.verbose: print("Used server: {}".format(api_client.getServer()))
@ -68,10 +68,10 @@ def send(args, api_client, settings=None):
# If we use dry option, exit now # If we use dry option, exit now
if args.dry: if args.dry:
if not args.json: print("Dry mode: paste will not be uploaded. Exiting…") if not settings['json']: print("Dry mode: paste will not be uploaded. Exiting…")
sys.exit(0) sys.exit(0)
if not args.json: print("Uploading paste…") if not settings['json']: print("Uploading paste…")
result = api_client.post(request) result = api_client.post(request)
if args.debug: print("Response:\t{}\n".format(result)) if args.debug: print("Response:\t{}\n".format(result))
@ -80,7 +80,7 @@ def send(args, api_client, settings=None):
if not result['status']: # return code is zero if not result['status']: # return code is zero
passphrase = paste.getHash() passphrase = paste.getHash()
if args.json: # JSON output if settings['json']: # JSON output
response = { response = {
'status': result['status'], 'status': result['status'],
'result': { 'result': {

4
pbincli/cli.py

@ -91,7 +91,7 @@ def main():
send_parser.add_argument("-L", "--mirrors", default=argparse.SUPPRESS, help="Comma-separated list of mirrors of service with scheme (default: None)") send_parser.add_argument("-L", "--mirrors", default=argparse.SUPPRESS, help="Comma-separated list of mirrors of service with scheme (default: None)")
send_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output") send_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output")
send_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output. Includes verbose output") send_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output. Includes verbose output")
send_parser.add_argument("--json", default=False, action="store_true", help="Print result in JSON format") send_parser.add_argument("--json", default=argparse.SUPPRESS, action="store_true", help="Print result in JSON format")
send_parser.add_argument("--dry", default=False, action="store_true", help="Invoke dry run") send_parser.add_argument("--dry", default=False, action="store_true", help="Invoke dry run")
send_parser.add_argument("stdin", help="Input paste text from stdin", nargs="?", type=argparse.FileType("r"), default=sys.stdin) send_parser.add_argument("stdin", help="Input paste text from stdin", nargs="?", type=argparse.FileType("r"), default=sys.stdin)
send_parser.set_defaults(func=pbincli.actions.send) send_parser.set_defaults(func=pbincli.actions.send)
@ -116,7 +116,6 @@ def main():
## ##
get_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output") get_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output")
get_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output. Includes verbose output") get_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output. Includes verbose output")
get_parser.add_argument("--json", default=False, action="store_true", help="Print result in JSON format")
get_parser.set_defaults(func=pbincli.actions.get) get_parser.set_defaults(func=pbincli.actions.get)
# a delete command # a delete command
@ -136,7 +135,6 @@ def main():
## ##
delete_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output") delete_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output")
delete_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output. Includes verbose output") delete_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output. Includes verbose output")
delete_parser.add_argument("--json", default=False, action="store_true", help="Print result in JSON format")
delete_parser.set_defaults(func=pbincli.actions.delete) delete_parser.set_defaults(func=pbincli.actions.delete)
# Add argcomplete trigger # Add argcomplete trigger

Loading…
Cancel
Save