|
|
|
@ -1,7 +1,6 @@
@@ -1,7 +1,6 @@
|
|
|
|
|
#!/usr/bin/env python |
|
|
|
|
# PYTHON_ARGCOMPLETE_OK |
|
|
|
|
import os, sys, argparse |
|
|
|
|
from distutils.util import strtobool |
|
|
|
|
|
|
|
|
|
import argcomplete |
|
|
|
|
|
|
|
|
@ -20,6 +19,16 @@ elif sys.platform == "darwin":
@@ -20,6 +19,16 @@ elif sys.platform == "darwin":
|
|
|
|
|
CONFIG_PATHS.append(os.path.join(os.getenv("HOME") or "~", "Library", "Application Support", "pbincli", "pbincli.conf")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def strtobool(value): |
|
|
|
|
try: |
|
|
|
|
return { |
|
|
|
|
'y': True, 'yes': True, 't': True, 'true': True, 'on': True, '1': True, |
|
|
|
|
'n': False, 'no': False, 'f': False, 'false': False, 'off': False, '0': False, |
|
|
|
|
}[str(value).lower()] |
|
|
|
|
except KeyError: |
|
|
|
|
raise ValueError('"{}" is not a valid bool value'.format(value)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_config(filename): |
|
|
|
|
"""Read config variables from a file""" |
|
|
|
|
settings = {} |
|
|
|
@ -81,7 +90,8 @@ def main():
@@ -81,7 +90,8 @@ 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("-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") |
|
|
|
|
send_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output. Includes verbose output") |
|
|
|
|
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("stdin", help="Input paste text from stdin", nargs="?", type=argparse.FileType("r"), default=sys.stdin) |
|
|
|
|
send_parser.set_defaults(func=pbincli.actions.send) |
|
|
|
@ -105,7 +115,7 @@ def main():
@@ -105,7 +115,7 @@ def main():
|
|
|
|
|
get_parser.add_argument("--auth-custom", default=argparse.SUPPRESS, help="Custom authorization header in JSON format") |
|
|
|
|
## |
|
|
|
|
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") |
|
|
|
|
get_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output. Includes verbose output") |
|
|
|
|
get_parser.set_defaults(func=pbincli.actions.get) |
|
|
|
|
|
|
|
|
|
# a delete command |
|
|
|
@ -124,7 +134,7 @@ def main():
@@ -124,7 +134,7 @@ def main():
|
|
|
|
|
delete_parser.add_argument("--auth-custom", default=argparse.SUPPRESS, help="Custom authorization header in JSON format") |
|
|
|
|
## |
|
|
|
|
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") |
|
|
|
|
delete_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output. Includes verbose output") |
|
|
|
|
delete_parser.set_defaults(func=pbincli.actions.delete) |
|
|
|
|
|
|
|
|
|
# Add argcomplete trigger |
|
|
|
@ -155,7 +165,8 @@ def main():
@@ -155,7 +165,8 @@ def main():
|
|
|
|
|
'auth': None, |
|
|
|
|
'auth_user': None, |
|
|
|
|
'auth_pass': None, |
|
|
|
|
'auth_custom': None |
|
|
|
|
'auth_custom': None, |
|
|
|
|
'json': False |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Configuration preference order: |
|
|
|
@ -182,7 +193,9 @@ def main():
@@ -182,7 +193,9 @@ def main():
|
|
|
|
|
# Re-validate PrivateBin instance URL |
|
|
|
|
CONFIG['server'] = validate_url_ending(CONFIG['server']) |
|
|
|
|
|
|
|
|
|
if args.debug: print("Whole configuration:\n{}\n".format(CONFIG)) |
|
|
|
|
if args.debug: |
|
|
|
|
print("Whole configuration:\n{}\n".format(CONFIG)) |
|
|
|
|
args.verbose = True |
|
|
|
|
api_client = PrivateBin(CONFIG) |
|
|
|
|
|
|
|
|
|
if hasattr(args, "func"): |
|
|
|
|