Appendix F — Add Options, Defaults, and Help Text Answers

Completed Check

The optional wordlist flag gives users flexibility while preserving a useful default. If the user provides --wordlist, argparse stores that path; if they don’t, it quietly stores the default for us. Very civilised.

import argparse


def build_argument_parser():
    parser = argparse.ArgumentParser(
        prog="bernauer",
        description="Fixture-backed subdomain bruteforcer for authorised practice.",
    )
    parser.add_argument("domain", help="domain to test, e.g. example.test")
    parser.add_argument(
        "-w",
        "--wordlist",
        default="data/wordlist.txt",
        help="path to a wordlist file",
    )
    return parser


args = build_argument_parser().parse_args(["example.test"])
print(args.domain)
print(args.wordlist)
example.test
data/wordlist.txt

The default keeps the beginner path short, and the flag keeps the tool flexible once you want to bring your own list. The parser description is also doing real work: it tells tired-terminal-you what the program is for before listing the arguments.

References: ArgumentParser, default, and help.