#!/usr/bin/env python3

import fire
from itertools import product
import pyRemembeR

def main(command, arg_dict, outfile, remember_file='remember_grid_sweep.RDS'):
    print(remember_file)
    remember = pyRemembeR.remember.Remember()
    remember.set_file(remember_file)
    if type(arg_dict) is not dict:
        arg_dict = eval(arg_dict)
    remember[outfile] = arg_dict
    remember.save_to_r()
    keys = []
    values = []
        
    for i,p in enumerate(arg_dict.items()):
        k,v = p
        keys.append(k)
        values.append(v)
        command = command + f" --{k} {{{i}}} "

    args_list = product(*values)

    with open(outfile,'w') as of:
        for args in args_list:
            of.write(command.format(*args) + '\n')

if __name__ == '__main__':
    fire.Fire(main)
