import re


def add_asic_arg(format_str, cmds_list, asic_num):
    """ 
    Add ASIC specific arg using the supplied string formatter 

    New commands are added for each ASIC. In case of a regex
    paramter, new regex is created for each ASIC.
    """
    updated_cmds = []
    for cmd in cmds_list:
        if isinstance(cmd, str):
            if "{}" in cmd:
                if asic_num == 1:
                    updated_cmds.append(cmd.format(""))
                else:
                    for asic in range(0, asic_num):
                        asic_arg = format_str.format(asic)
                        updated_cmds.append(cmd.format(asic_arg))
            else:
                updated_cmds.append(cmd)
        else:
            if "{}" in cmd.pattern:
                if asic_num == 1:
                    mod_pattern = cmd.pattern.format("")
                    updated_cmds.append(re.compile(mod_pattern))
                else:
                    for asic in range(0, asic_num):
                        asic_arg = format_str.format(asic)
                        mod_pattern = cmd.pattern.format(asic_arg)
                        updated_cmds.append(re.compile(mod_pattern))
            else:
                updated_cmds.append(cmd)
    return updated_cmds