You cannot post messages because only members can post, and you are not currently a member.
Description:
Mailing list for users of the argparse Python module.
|
|
|
Subparsers, set_defaults, and func
|
| |
I'm trying to set up a command-line parser for basically three commands. Let's call the application "runner." The three commands are as follows: runner start runner stop runner install 1.2.3 As you can see, the "install" command takes an additional version-number argument. Here's what I have: parser = argparse.ArgumentParser()... more »
|
|
argparse eating more than one '--'
|
| |
I am converting some scripts from optparse to argparse, and discovered
a problem. Argparse seems to be eating more double-dashes than it
should, preventing the nesting of several commands on a cmdline, each
of which take '--' to mean "all the rest of the cmdline are
positionals, not options". Consider this toy reimplementation of... more »
|
|
Defining argument group for help and version
|
| |
Hello, Sometimes its helpful to separate the help and version options (which provide script information) from those used in running the script normally. I can create a custom argument group that includes the help and version options as follows: p = argparse.ArgumentParser(descri ption=script_description,... more »
|
|
multiple usage strings
|
| |
Hello, Is there a recommended way to leverage argparse to define multiple usage strings (for example, to illustrated mutually exclusive use cases). E.g.: myscript.py [-h] [--version] myscript.py [-f FOO] infile [infile ...] The best I've come up with so far is to create sets of specifications for add_parser. First, create a parser for each set just to get the... more »
|
|
custom python shell (cmd + argparse)
|
| |
I want to make a custom interactive shell. I figured using the cmd
module might be most convenient. basically make a new class inheriting
cmd and then add commands using the do_cmd convention.
Because this is a shell I will override the invalid argument default
exit behavior of argparse so that instead of exiting I get the shell... more »
|
|
mutually exclusive groups + arguments
|
| |
Guys, after looking for this a lot, I had to come here and ask. Even
checked examples at [link]
I want this behaviour:
( -f FILENAME | -i IP -u USER -p PASSWORD )
You see? If it's -f, then just a filename, otherwise if -i, need -u... more »
|
|
Action not invoked for default value
|
| |
Hi there,
Have been playing with a custom Action that automatically sets logging
verbosity based on a command line argument. Something that surprised
me was that if a default value is specified and the user does not
specify the flag then the action is never called. In my case, this
meant that the default logging level was never set.... more »
|
|
Nested subparsers?
|
| |
Hi Steven,
How can I use the argparse in this way:
...
NOTE: each cmd{#} defined as a subparser with its unique set of
parameters.
It's close to the behavior of "svn commit" for example with an
addition of a mandatory
parameter before any subparser, this parameter determines which
subparser to call, say:... more »
|
|
how to tell parse_known_args to not parse all known args
|
| |
Hi all,
I guess my question is a bit lame, but here's the problem:
I have a bunch submodules of a package that work as standalone
scripts, each creating its own ArgumentParser. Now, I also have a
frontend script that takes as input the name of a script. The frontend
parses the command line with parse_known_args, imports the requested... more »
|
|
unable to create "subgroups" under mutually exclusive group
|
| |
Dear developer,
I am new to Python and have a question: is there any way in argparse
to create "subgroups" under mutually exclusive group? For example, I
would like to group four options a, b, c, and d into two mutually
exclusive subgroups ("a","b") and ("c","d"). And within each group, I
hope both of the arguments are "required", for example, if "--b"... more »
|
|
|