import shlex


def get_flexbar_options_string(args):
    """ Extract the flags and options specified for flexbar added with
    add_flexbar_options.

    Parameters
    ---------
    args: argparse.Namespace
        The parsed arguments

    Returns
    -------
    flexbar_options: string
        a string containing flexbar options suitable to pass to another command
    """

    args_dict = vars(args)

    s = ""
    if args_dict['flexbar_options']:
        flexbar_option_str = "--flexbar-options {}".format(
            ' '.join(shlex.quote(flx_op) for flx_op in args_dict['flexbar_options']))
        s = "{}".format(' '.join([s, flexbar_option_str]))

    return s