def generate_commands()

in generate_commands_from_synopsis.py [0:0]


def generate_commands(results, graph, avg_options=3, pipe_prob=0.3):
    idx = None
    cmds = []
    texts = []
    while True:
        cmd, text = generate_single_command(results, avg_options=avg_options, idx=idx)
        cmds.append(cmd)
        texts.append(text)
        p = np.random.rand()

        if p > pipe_prob:
            break

        cmd_name = get_cmd_name(cmd)
        next = graph.get(cmd_name, None)
        if next is None:
            break
        next_cmd = np.random.choice(list(graph[cmd_name]))
        idx = np.where(results['cmd'] == next_cmd)[0][0]

    cmd = " | ".join(cmds)
    text = " and ".join(texts)

    extra_cmds = ["{} | wc -l", "{} | grep ARG", "VAR=$({})", "VAR=`{}`"]
    extra_texts = [
        ["How many {}", "Count lines of {}", "Get number of {}"],
        ["Find all {} with ARG", "Which {} has ARG"],
        ["Set variable VAR to the {}", "Set variable VAR to {}"],
        ["Set variable VAR to the {}", "Set variable VAR to {}"]
    ]
    if np.random.rand() < 0.01:
        cmd_idx = np.random.randint(len(extra_cmds))
        cmd = extra_cmds[cmd_idx].format(cmd)
        text = np.random.choice(extra_texts[cmd_idx]).format(text)

    return cmd, text