zenlotus / argparse

Automatically exported from code.google.com/p/argparse
Other
0 stars 0 forks source link

values to arguments should be mandatred to be placed immediate #42

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Consider this example:

        # SET command options
        #
        parser_set = subparsers.add_parser('set', parents=[global_options])
        parser_set.set_defaults(func=setter)

        parser_set.add_argument('set',
                          help="Generate a signature file",
                          action="store", type=str, metavar="apt-offline.sig",
                          default="apt-offline.sig")

        #TODO: Handle nargs here.
        parser_set.add_argument("--install-packages",
dest="set_install_packages", help="Packages that need to be installed",
                          action="store", type=str, nargs='*', metavar="PKG")

        parser_set.add_argument("--install-src-packages",
dest="set_install_src_packages", help="Source Packages that need to be
installed",
                          action="store", type=str, nargs='*',
metavar="SOURCE PKG")

"set" here is a command/argument which expects a value, in this case a file.
Set also has many options. Like the above ones with nargs='*'.

Since argparse is not mandating the placement of the value for the "set"
argument, it fails if that value is places after the option/argument of
type nargs='*'

rrs@champaran:~/devel/apt-offline/apt-offline  (master)$ apt-offline  set
--install-packages foo bar /tmp/foo.uris
usage: apt-offline set [-h] [--verbose] [--test-windows]
                       [--install-packages [PKG [PKG ...]]]
                       [--install-src-packages [SOURCE PKG [SOURCE PKG ...]]]
                       [--src-build-dep] [--release release_name] [--update]
                       [--upgrade] [--upgrade-type upgrade]
                       apt-offline.sig
apt-offline set: error: too few arguments
rrs@champaran:~/devel/apt-offline/apt-offline  (master)$ less
AptOfflineCoreLib.py
rrs@champaran:~/devel/apt-offline/apt-offline  (master)$ sudo apt-offline 
set /tmp/foo.uris --install-packages foo bar
[sudo] password for rrs:

Generating database of package foo, bar,  and its dependencies.

What is the expected output? What do you see instead?
Placements should either be mandated or else argparse should be able to
handle the case I've mentioned above.

What version of the product are you using? On what operating system?
argparse 1.0.1
Linux

Original issue reported on code.google.com by riteshra...@gmail.com on 1 Nov 2009 at 11:13

GoogleCodeExporter commented 9 years ago
Ah!! Looks like Steve is already aware of the problem (Defect #20)

Original comment by riteshra...@gmail.com on 1 Nov 2009 at 11:14

GoogleCodeExporter commented 9 years ago

Original comment by steven.b...@gmail.com on 2 Nov 2009 at 4:41