move argparsing to parseArgs()

This commit is contained in:
randomuser 2021-07-20 12:39:53 -05:00
parent c048fda55a
commit 4eda8f6d2c
1 changed files with 6 additions and 2 deletions

View File

@ -188,14 +188,18 @@ class GopherHandler(socketserver.BaseRequestHandler, GopherServerLogic):
log = Logger() log = Logger()
if __name__ == "__main__": def parseArgs():
parse = argparse.ArgumentParser() parse = argparse.ArgumentParser()
parse.add_argument("-u", "--user", default="nobody", help="user to change to on startup") parse.add_argument("-u", "--user", default="nobody", help="user to change to on startup")
parse.add_argument("-g", "--group", default="nobody", help="group to change to on startup") parse.add_argument("-g", "--group", default="nobody", help="group to change to on startup")
parse.add_argument("-s", "--host", default="localhost", help="host to host on") parse.add_argument("-s", "--host", default="localhost", help="host to host on")
parse.add_argument("-p", "--port", default=70, type=int, help="port to host on") parse.add_argument("-p", "--port", default=70, type=int, help="port to host on")
parse.add_argument("-d", "--dir", default="/var/gopher", help="directory to host from") parse.add_argument("-d", "--dir", default="/var/gopher", help="directory to host from")
args = parse.parse_args() return parse.parse_args()
if __name__ == "__main__":
args = parseArgs()
log.log("arguments parsed") log.log("arguments parsed")
switchgrp = grp.getgrnam(args.group).gr_gid switchgrp = grp.getgrnam(args.group).gr_gid