from typing import List


def parse_kaldi_config_file(file_path: str, allow_space=True) -> List[str]:
    """Return a list of arguments from a kaldi config file

    Parameters
    ----------
    file_path : str
        Points to the config file in question
    allow_spaces : bool, optional
        If ``True``, treat the first space on a line as splitting key
        and value if no equals sign exists on the line. If ``False``, no
        equals sign will chunk the whole line (as if a boolean flag).
        Kaldi does not split on spaces, but python does. Note that
        `allow_spaces` does not split the entire line on spaces, unlike
        shell arguments.
    """
    args = []
    with open(file_path) as config_file:
        for line_no, line in enumerate(config_file):
            line = line.split("#")[0].strip()
            if not line:
                continue
            if not line.startswith("--"):
                raise ValueError(
                    "Reading config file {} : line {} does not look "
                    "like a line from a Kaldi command-line program's "
                    "config file: should be of the form --x=y. Note: "
                    "config files intended to be sourced by shell "
                    "scripts lack the '--'.".format(file_path, line_no + 1)
                )
            equals_index = line.find("=")
            if equals_index == 2:
                raise ValueError("Invalid option (no key): ".format(line))
            elif allow_space and equals_index == -1:
                space_index = line.find(" ")
                assert space_index != 2
                if space_index == -1:
                    args.append(line)
                else:
                    args.extend([line[:space_index], line[space_index + 1 :]])
            else:
                args.append(line)
    return args