Top-rated recipes tagged "option"http://code.activestate.com/recipes/tags/option/top/2011-05-13T13:53:56-07:00ActiveState Code Recipesargdeclare: declarative interface to argparse (Python)
2010-03-02T00:05:40-08:00Shakeeb Alirezahttp://code.activestate.com/recipes/users/4172101/http://code.activestate.com/recipes/576935-argdeclare-declarative-interface-to-argparse/
<p style="color: grey">
Python
recipe 576935
by <a href="/recipes/users/4172101/">Shakeeb Alireza</a>
(<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/cmdln/">cmdln</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/getopt/">getopt</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/option/">option</a>).
Revision 5.
</p>
<p>This is an implementation of the interface provided by the <a href="http://code.google.com/p/cmdln/">cmdln</a> module but using <a href="http://code.google.com/p/argparse/">argparse</a> to provide the option/arg heavy parsing.</p>
<p>An example of usage is provided in the <code>test</code> function, which should produce the following from the command line:</p>
<p>$ python argdeclare.py --help</p>
<pre class="prettyprint"><code>usage: argdeclare.py [-h] [-v] {uninstall,install,delete} ...
a description of the test app
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
subcommands:
valid subcommands
{uninstall,install,delete}
additional help
delete help text for delete subcmd
install help text for install subcmd
uninstall help text for uninstall subcmd
</code></pre>
<p>$ python argdeclare.py install --help</p>
<pre class="prettyprint"><code>usage: argdeclare.py install [-h] [-t TYPE] [--log] [-f] package
positional arguments:
package package to be (un)installed
optional arguments:
-h, --help show this help message and exit
-t TYPE, --type TYPE specify type of package
--log, -l log is on
-f, --force force through installation
</code></pre>
<p>enjoy!</p>
<p>SA</p>
Get a list from a ConfigParser option (Python)
2011-05-13T13:53:56-07:00Georges Martinhttp://code.activestate.com/recipes/users/4177973/http://code.activestate.com/recipes/577694-get-a-list-from-a-configparser-option/
<p style="color: grey">
Python
recipe 577694
by <a href="/recipes/users/4177973/">Georges Martin</a>
(<a href="/recipes/tags/configparser/">configparser</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/option/">option</a>).
Revision 2.
</p>
<p>Return a list from a ConfigParser option. By default, split on a comma and strip whitespaces.</p>
Command Line Options and Args Hate'em? Me Too! (Python)
2010-06-03T19:16:43-07:00AJ. Mayorgahttp://code.activestate.com/recipes/users/4173476/http://code.activestate.com/recipes/577238-command-line-options-and-args-hateem-me-too/
<p style="color: grey">
Python
recipe 577238
by <a href="/recipes/users/4173476/">AJ. Mayorga</a>
(<a href="/recipes/tags/option/">option</a>, <a href="/recipes/tags/optionparser/">optionparser</a>, <a href="/recipes/tags/option_parsing/">option_parsing</a>).
Revision 5.
</p>
<p>I am all about trying to make development easier and reduce mundane tasks, especially
dealing with commandline args and getopt, OptParse, argparse sorry just not a fan. Argparse-cli
is really cool if you want low level control. I just got tired of writing tons of conditionals, labels, limited type handling, and having to do all of it over and over for every commandline project so help end the madness I wrote PyOpts. </p>