- if len(sys.argv) > 1:
- for filename in sys.argv[1:]:
- if filename == "-":
- parse_logfile(sys.stdin, "(stdin)")
- else:
- with open(filename) as file:
- parse_logfile(file, filename)
- else:
- parse_logfile(sys.stdin, "(stdin)")
+ # Create an argument parser using the file's docsctring as its
+ # description.
+ from argparse import ArgumentParser, FileType
+ parser = ArgumentParser(description = __doc__)
+
+ # Parse zero or more positional arguments into a list of
+ # "logfiles". If none are given, read from stdin instead.
+ parser.add_argument("logfiles",
+ metavar="LOGFILE",
+ type=FileType("r"),
+ nargs="*",
+ default=[sys.stdin],
+ help="djbdns logfile to process (default: stdin)")
+
+ args = parser.parse_args()
+ for f in args.logfiles:
+ parse_logfile(f)
+