|
|
@ -1,7 +1,6 @@ |
|
|
|
#!/usr/bin/env python |
|
|
|
#!/usr/bin/env python |
|
|
|
# PYTHON_ARGCOMPLETE_OK |
|
|
|
# PYTHON_ARGCOMPLETE_OK |
|
|
|
import os, sys, argparse |
|
|
|
import os, sys, argparse |
|
|
|
from distutils.util import strtobool |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import argcomplete |
|
|
|
import argcomplete |
|
|
|
|
|
|
|
|
|
|
@ -20,6 +19,16 @@ elif sys.platform == "darwin": |
|
|
|
CONFIG_PATHS.append(os.path.join(os.getenv("HOME") or "~", "Library", "Application Support", "pbincli", "pbincli.conf")) |
|
|
|
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): |
|
|
|
def read_config(filename): |
|
|
|
"""Read config variables from a file""" |
|
|
|
"""Read config variables from a file""" |
|
|
|
settings = {} |
|
|
|
settings = {} |
|
|
@ -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("-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") |
|
|
|
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("--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) |
|
|
@ -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("--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("-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) |
|
|
|
get_parser.set_defaults(func=pbincli.actions.get) |
|
|
|
|
|
|
|
|
|
|
|
# a delete command |
|
|
|
# a delete command |
|
|
@ -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("--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("-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) |
|
|
|
delete_parser.set_defaults(func=pbincli.actions.delete) |
|
|
|
|
|
|
|
|
|
|
|
# Add argcomplete trigger |
|
|
|
# Add argcomplete trigger |
|
|
@ -155,7 +165,8 @@ def main(): |
|
|
|
'auth': None, |
|
|
|
'auth': None, |
|
|
|
'auth_user': None, |
|
|
|
'auth_user': None, |
|
|
|
'auth_pass': None, |
|
|
|
'auth_pass': None, |
|
|
|
'auth_custom': None |
|
|
|
'auth_custom': None, |
|
|
|
|
|
|
|
'json': False |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Configuration preference order: |
|
|
|
# Configuration preference order: |
|
|
@ -182,7 +193,9 @@ def main(): |
|
|
|
# Re-validate PrivateBin instance URL |
|
|
|
# Re-validate PrivateBin instance URL |
|
|
|
CONFIG['server'] = validate_url_ending(CONFIG['server']) |
|
|
|
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) |
|
|
|
api_client = PrivateBin(CONFIG) |
|
|
|
|
|
|
|
|
|
|
|
if hasattr(args, "func"): |
|
|
|
if hasattr(args, "func"): |
|
|
|