# Buggy code
def main(argv=sys.argv[1:]):
    # type: (List[str]) -> int
    locale.setlocale(locale.LC_ALL, "")
    sphinx.locale.init_console(os.path.join(package_dir, "locale"), "sphinx")

    if not color_terminal():
        nocolor()

    # parse options
    parser = get_parser()
    try:
        args = parser.parse_args(argv)
    except SystemExit as err:
        return err.code

    d = vars(args)
    # delete None or False value
    d = dict((k, v) for k, v in d.items() if v is not None)

    try:
        if "quiet" in d:
            if not set(["project", "author"]).issubset(d):
                print(
                    __(""""quiet" is specified, but any of "project" or \
"author" is not specified.""")
                )
                return 1

        if set(["quiet", "project", "author"]).issubset(d):
            # quiet mode with all required params satisfied, use default
            d.setdefault("version", "")
            d.setdefault("release", d["version"])
            d2 = DEFAULTS.copy()
            d2.update(d)
            d = d2

            if not valid_dir(d):
                print()
                print(
                    bold(
                        __(
                            "Error: specified path is not a directory, or sphinx"
                            " files already exist."
                        )
                    )
                )
                print(
                    __(
                        "sphinx-quickstart only generate into a empty directory."
                        " Please specify a new root path."
                    )
                )
                return 1
        else:
            ask_user(d)
    except (KeyboardInterrupt, EOFError):
        print()
        print("[Interrupted.]")
        return 130  # 128 + SIGINT

    # decode values in d if value is a Python string literal
    for key, value in d.items():
        if isinstance(value, binary_type):
            d[key] = term_decode(value)

    # handle use of CSV-style extension values
    d.setdefault("extensions", [])
    for ext in d["extensions"][:]:
        if "," in ext:
            d["extensions"].remove(ext)
            d["extensions"].extend(ext.split(","))

    for variable in d.get("variables", []):
        try:
            name, value = variable.split("=")
            d[name] = value
        except ValueError:
            print(__("Invalid template variable: %s") % variable)

    generate(d, overwrite=False, templatedir=args.templatedir)
    return 0


# Traceback (locale.Error)
Traceback (most recent call last):
File "/private/tmp/issue/venv/bin/sphinx-quickstart", line 11, in <module>
sys.exit(main())
File "/private/tmp/issue/venv/lib/python3.7/site-packages/sphinx/cmd/quickstart.py", line 616, in main
locale.setlocale(locale.LC_ALL, '')
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/locale.py", line 604, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting

# Fixed code
def main(argv=sys.argv[1:]):
    # type: (List[str]) -> int
    sphinx.locale.setlocale(locale.LC_ALL, "")
    sphinx.locale.init_console(os.path.join(package_dir, "locale"), "sphinx")

    if not color_terminal():
        nocolor()

    # parse options
    parser = get_parser()
    try:
        args = parser.parse_args(argv)
    except SystemExit as err:
        return err.code

    d = vars(args)
    # delete None or False value
    d = dict((k, v) for k, v in d.items() if v is not None)

    try:
        if "quiet" in d:
            if not set(["project", "author"]).issubset(d):
                print(
                    __(""""quiet" is specified, but any of "project" or \
"author" is not specified.""")
                )
                return 1

        if set(["quiet", "project", "author"]).issubset(d):
            # quiet mode with all required params satisfied, use default
            d.setdefault("version", "")
            d.setdefault("release", d["version"])
            d2 = DEFAULTS.copy()
            d2.update(d)
            d = d2

            if not valid_dir(d):
                print()
                print(
                    bold(
                        __(
                            "Error: specified path is not a directory, or sphinx"
                            " files already exist."
                        )
                    )
                )
                print(
                    __(
                        "sphinx-quickstart only generate into a empty directory."
                        " Please specify a new root path."
                    )
                )
                return 1
        else:
            ask_user(d)
    except (KeyboardInterrupt, EOFError):
        print()
        print("[Interrupted.]")
        return 130  # 128 + SIGINT

    # decode values in d if value is a Python string literal
    for key, value in d.items():
        if isinstance(value, binary_type):
            d[key] = term_decode(value)

    # handle use of CSV-style extension values
    d.setdefault("extensions", [])
    for ext in d["extensions"][:]:
        if "," in ext:
            d["extensions"].remove(ext)
            d["extensions"].extend(ext.split(","))

    for variable in d.get("variables", []):
        try:
            name, value = variable.split("=")
            d[name] = value
        except ValueError:
            print(__("Invalid template variable: %s") % variable)

    generate(d, overwrite=False, templatedir=args.templatedir)
    return 0