def _get_command(path, command_directory):
    """
    Args:
        path: The pathlib.Path to _compile_command file.
        command_directory: The directory commands are run from.
    Returns a string to stick in compile_commands.json.
    """

    with path.open("r") as f:
        contents = f.read().split("\0")
        if len(contents) != 2:
            # Old/incomplete file or something; silently ignore it.
            return None
        if contents[1].startswith("external/"):
            # Do not include compilation commands for depdendencies
            return None
        return """{
    "directory": "%s",
    "command": "%s",
    "file": "%s"
    }""" % (command_directory, contents[0].replace('"', '\\"'), contents[1])