Improve argparse

This commit is contained in:
Michael Lazar 2019-08-04 14:11:22 -04:00
parent ba9c77cc11
commit 16c2140d2b
1 changed files with 25 additions and 8 deletions

View File

@ -242,19 +242,36 @@ class GeminiServer:
print(message, file=sys.stderr) print(message, file=sys.stderr)
if __name__ == "__main__": def run_server():
parser = argparse.ArgumentParser(
parser = argparse.ArgumentParser(prog="jetforce") prog="jetforce",
parser.add_argument("--host", default="127.0.0.1") description="An Experimental Gemini Protocol Server",
parser.add_argument("--port", type=int, default=1965) formatter_class=argparse.ArgumentDefaultsHelpFormatter,
parser.add_argument("--ssl-certfile", metavar="FILE", default="localhost.crt") )
parser.add_argument("--ssl-keyfile", metavar="FILE", default="localhost.key") parser.add_argument("--host", help="Server host", default="127.0.0.1")
parser.add_argument("--port", help="Server port", type=int, default=1965)
parser.add_argument(
"--tls-certfile",
help="TLS certificate file",
metavar="FILE",
default="localhost.crt",
)
parser.add_argument(
"--tls-keyfile",
help="TLS private key file",
metavar="FILE",
default="localhost.key",
)
args = parser.parse_args() args = parser.parse_args()
server = GeminiServer( server = GeminiServer(
host=args.host, host=args.host,
port=args.port, port=args.port,
ssl_context=(args.ssl_certfile, args.ssl_keyfile), ssl_context=(args.tls_certfile, args.tls_keyfile),
app=EchoApp, app=EchoApp,
) )
asyncio.run(server.run()) asyncio.run(server.run())
if __name__ == "__main__":
run_server()