def add_args(cmd, args_dict):
    """
    Insert the command line arguments from `args_dict` into a chef run command.
    Assumes `cmd` contains the substring `--token` and inserts args right before
    instead of appending to handle the case where cmd contains extra options. 
    """
    args_str = ''
    for argk, argv in args_dict.items():
        if argv is not None:
            args_str += ' ' + argk + '=' + argv + ' '
        else:
            args_str += ' ' + argk + ' '
    return cmd.replace('--token', args_str + ' --token')