import shlex


def get_star_options_string(args):
    """ Extract the flags and options specified for STAR added with 
    add_star_options.

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

    Returns
    -------
    star_options: string
        a string containing STAR options suitable to pass to another command
    """

    args_dict = vars(args)

    star_options = ['star_executable']

    # create a new dictionary mapping from the flag to the value
    star_options = {'--{}'.format(o.replace('_', '-')): args_dict[o]
        for o in star_options if args_dict[o] is not None}

    s = ' '.join("{} {}".format(k, shlex.quote(v))
                    for k, v in star_options.items())

    # if additional options
    if args_dict['star_options']:
        star_additional_options_str = "--star-options {}".format(
            ' '.join(shlex.quote(star_option) for star_option
                     in args_dict['star_options']))
        s = "{}".format(' '.join([s, star_additional_options_str]))

    return s