PBinCLI/pbincli.py

57 lines
2.7 KiB
Python
Raw Normal View History

#! /usr/bin/env python
2017-02-18 18:00:40 +00:00
import os
import sys
import argparse
import pbincli.actions
from pbincli.utils import PBinCLIException
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(title="actions", help="List of commands")
2017-02-18 18:27:24 +00:00
2017-02-18 18:00:40 +00:00
# a send command
2017-02-18 18:27:24 +00:00
send_parser = subparsers.add_parser("send", description="Send data to PrivateBin instance", usage="""
%(prog)s --burn --discus --expire 1day --format plaintext \\
2017-02-20 17:56:37 +00:00
--comment "My file" --password mypass image.txt"""
2017-02-18 18:27:24 +00:00
)
2017-02-20 21:14:56 +00:00
send_parser.add_argument("-B", "--burn", default=False, action="store_true", help="burn sent paste after reading")
2017-02-20 17:56:37 +00:00
send_parser.add_argument("-c", "--comment", help="comment in quotes")
2017-02-20 21:14:56 +00:00
send_parser.add_argument("-D", "--discus", default=False, action="store_true", help="open discussion of sent paste")
send_parser.add_argument("-E", "--expire", default="1day", action="store", help="expiration of paste (default: 1day)")
send_parser.add_argument("-F", "--format", default="plaintext", action="store", choices=["plaintext", "syntaxhighlighting", "markdown"], help="format of paste (default: plaintext)")
2017-02-20 22:27:32 +00:00
send_parser.add_argument("-p", "--password", help="password for encrypting paste")
2017-02-20 21:14:56 +00:00
send_parser.add_argument("-d", "--debug", default=False, action="store_true", help="enable debug")
send_parser.add_argument("-f", "--file", help="example: image.jpg or full path to file")
2017-02-18 18:00:40 +00:00
send_parser.set_defaults(func=pbincli.actions.send)
2017-02-18 18:27:24 +00:00
2017-02-20 12:13:42 +00:00
get_parser = subparsers.add_parser("get", description="Get data from PrivateBin instance", usage="""
%(prog)s pasteid#password"""
)
get_parser.add_argument("pasteinfo", help="example: aabb#cccddd")
2017-02-20 21:14:56 +00:00
get_parser.add_argument("-d", "--debug", default=False, action="store_true", help="enable debug")
2017-02-20 22:27:32 +00:00
get_parser.add_argument("-p", "--password", help="password for decrypting paste")
2017-02-20 12:13:42 +00:00
get_parser.set_defaults(func=pbincli.actions.get)
delete_parser = subparsers.add_parser("delete", description="Delete paste from PrivateBin instance using token", usage="""
%(prog)s --paste aabb --token aabbcc"""
)
delete_parser.add_argument("-p", "--paste", required=True, help="paste id")
delete_parser.add_argument("-t", "--token", required=True, help="delete token")
delete_parser.add_argument("-d", "--debug", default=False, action="store_true", help="enable debug")
delete_parser.set_defaults(func=pbincli.actions.delete)
2017-02-18 18:00:40 +00:00
# parse arguments
args = parser.parse_args()
if hasattr(args, "func"):
try:
args.func(args)
except PBinCLIException as pe:
print("PBinCLI error: {}".format(pe))
sys.exit(1)
else:
parser.print_help()
if __name__ == "__main__":
main()