Popular recipes tagged "getopt"http://code.activestate.com/recipes/tags/getopt/popular/2010-03-02T00:05:40-08: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>
getopt (C)
2009-07-16T01:55:53-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576769-getopt/
<p style="color: grey">
C
recipe 576769
by <a href="/recipes/users/4170398/">J Y</a>
(<a href="/recipes/tags/getopt/">getopt</a>).
Revision 3.
</p>
<p>working with getopt</p>