Files
CN2021/client.py
2021-03-24 16:35:12 +01:00

31 lines
966 B
Python

#!/usr/bin/env python3
import argparse
import logging
import sys
from client import command as cmd
def main():
parser = argparse.ArgumentParser(description='HTTP Client')
parser.add_argument("--verbose", "-v", action='count', default=0, help="Increase verbosity level of logging")
parser.add_argument("--command", "-c", help="HEAD, GET, PUT or POST", default="GET")
parser.add_argument("--port", "-p", help="The port used to connect with the server", default=80)
parser.add_argument("URI", help="The URI to connect to")
arguments = parser.parse_args()
logging.basicConfig(level=logging.ERROR - (10 * arguments.verbose))
logging.debug("Arguments: %s", arguments)
command = cmd.create(arguments.command, arguments.URI, arguments.port)
command.execute()
try:
main()
except Exception as e:
print("[ABRT] Internal error: " + str(e), file=sys.stderr)
logging.debug("Internal error", exc_info=e)
sys.exit(70)