_fix_argv() fails with Argparse's action='append'

Bug #1685630 reported by Jordan Pittier
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
os-client-config
New
Undecided
Unassigned

Bug Description

Python Argparse supports the 'append' action [1] which is super handy to allow a user to repeat several times the same argument, each time with different values.

This doesn't work with occ that tries to "fix argv" but raises this error:

os_client_config.exceptions.OpenStackConfigException: The following options were given: '--foo,--foo' which contain duplicates except that one has _ and one has -. There is no sane way for us to know what you're doing. Remove the duplicate option and try again

Reproducer:

--------------------------------------------------------------------------------
import argparse
import sys

import os_client_config

cloud_config = os_client_config.OpenStackConfig()
parser = argparse.ArgumentParser()

parser.add_argument('--foo', action='append')

cloud_config.register_argparse_arguments(parser, sys.argv)

options = parser.parse_args()

cloud = cloud_config.get_one_cloud(argparse=options)

print(repr(options))
--------------------------------------------------------------------------------

python main2.py --foo 1 --foo 2

[1] https://docs.python.org/3/library/argparse.html#action

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix proposed to os-client-config (master)

Related fix proposed to branch: master
Review: https://review.openstack.org/459115

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to os-client-config (master)

Reviewed: https://review.openstack.org/459115
Committed: https://git.openstack.org/cgit/openstack/os-client-config/commit/?id=ff2c06c30538edb9cb47b83f0a194f7893a7f458
Submitter: Jenkins
Branch: master

commit ff2c06c30538edb9cb47b83f0a194f7893a7f458
Author: Jordan Pittier <email address hidden>
Date: Sun Apr 23 17:42:47 2017 +0200

    Make _fix_argv() somewhat compatible with Argparse action='append'

    Python Argparse supports the 'append' action [1] which is super handy to allow
    a user to repeat several times the same argument, each time with different
    values.

    This doesn't work with occ that tries to "fix argv" but raises this error:

    os_client_config.exceptions.OpenStackConfigException: The following options
    were given: '--foo,--foo' which contain duplicates except that one has _
    and one has -. There is no sane way for us to know what you're doing.
    Remove the duplicate option and try again

    This patch tweak the _fix_argv() function so that it doesn't explode
    if the duplicate option has no '_' not '-' in its name.

    Change-Id: I4f06b6aff8d3ab1df45637399bc3a9b4b61764a9
    Related-bug: #1685630

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.