def get_runs(runs, selected_runs, cmdline):
    """Selects which run(s) to execute based on parts of the command-line.

    Will return an iterable of run numbers. Might also fail loudly or exit
    after printing the original command-line.
    """
    name_map = dict((r['id'], i) for i, r in enumerate(runs) if 'id' in r)
    run_list = []

    def parse_run(s):
        try:
            r = int(s)
        except __HOLE__:
            logging.critical("Error: Unknown run %s", s)
            raise UsageError
        if r < 0 or r >= len(runs):
            logging.critical("Error: Expected 0 <= run <= %d, got %d",
                             len(runs) - 1, r)
            sys.exit(1)
        return r

    if selected_runs is None:
        run_list = list(irange(len(runs)))
    else:
        for run_item in selected_runs.split(','):
            run_item = run_item.strip()
            if run_item in name_map:
                run_list.append(name_map[run_item])
                continue

            sep = run_item.find('-')
            if sep == -1:
                run_list.append(parse_run(run_item))
            else:
                if sep > 0:
                    first = parse_run(run_item[:sep])
                else:
                    first = 0
                if sep + 1 < len(run_item):
                    last = parse_run(run_item[sep + 1:])
                else:
                    last = len(runs) - 1
                if last < first:
                    logging.critical("Error: Last run number should be "
                                     "greater than the first")
                    sys.exit(1)
                run_list.extend(irange(first, last + 1))

    # --cmdline without arguments: display the original command-line
    if cmdline == []:
        print("Original command-lines:")
        for run in run_list:
            print(' '.join(shell_escape(arg)
                           for arg in runs[run]['argv']))
        sys.exit(0)

    return run_list
dataset/ETHPy150Open ViDA-NYU/reprozip/reprounzip/reprounzip/unpackers/common/misc.py/get_runs