cvs: peardoc /en/package/console console-commandline.xml /en/package/console/console-commandline creating-the-parser.xml examples.xml intro.xml
populating-the-parser.xml

From: Date: Mon, 19 May 2008 13:54:12 +0000
Subject: cvs: peardoc /en/package/console console-commandline.xml /en/package/console/console-commandline creating-the-parser.xml examples.xml intro.xml
populating-the-parser.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-10786@lists.php.net to get a copy of this message
izi Mon May 19 13:54:12 2008 UTC Modified files: /peardoc/en/package/console console-commandline.xml /peardoc/en/package/console/console-commandline creating-the-parser.xml examples.xml intro.xml populating-the-parser.xml Log: * added optparse link; * moved type and required info to their own columns; * added php tags around examples; * fixed typo in password action; * some cosmetic changes.

http://cvs.php.net/viewvc.cgi/peardoc/en/package/console/console-commandline.xml?r1=1.2&r2=1.3&diff_format=u Index: peardoc/en/package/console/console-commandline.xml diff -u peardoc/en/package/console/console-commandline.xml:1.2 peardoc/en/package/console/console-commandline.xml:1.3 --- peardoc/en/package/console/console-commandline.xml:1.2 Mon May 19 12:33:40 2008 +++ peardoc/en/package/console/console-commandline.xml Mon May 19 13:54:12 2008 @@ -1,14 +1,13 @@ -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <sect1 id="package.console.console-commandline"> <title>Console_CommandLine</title> - <para> <classname>Console_CommandLine</classname> is a full featured package for - managing command line options and arguments highly inspired from python - optparse module, it allows the developer to easily build complex command - line interfaces. + managing command line options and arguments highly inspired from the + <ulink url="http://docs.python.org/lib/module-optparse.html">python + optparse module</ulink>, it allows the developer to easily build + complex command line interfaces. </para> - &package.console.console-commandline.intro; &package.console.console-commandline.creating-the-parser; &package.console.console-commandline.populating-the-parser; http://cvs.php.net/viewvc.cgi/peardoc/en/package/console/console-commandline/creating-the-parser.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/console/console-commandline/creating-the-parser.xml diff -u peardoc/en/package/console/console-commandline/creating-the-parser.xml:1.1 peardoc/en/package/console/console-commandline/creating-the-parser.xml:1.2 --- peardoc/en/package/console/console-commandline/creating-the-parser.xml:1.1 Mon May 19 12:33:40 2008 +++ peardoc/en/package/console/console-commandline/creating-the-parser.xml Mon May 19 13:54:12 2008 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.console.console-commandline.creating-the-parser"> <refnamediv> <refname>Creating the parser</refname> @@ -18,40 +18,57 @@ <para> <table> <title>Available parameters</title> - <tgroup cols="2"> + <tgroup cols="4"> + <thead> + <row> + <entry>name</entry> + <entry>type</entry> + <entry>required</entry> + <entry>description</entry> + </row> + </thead> <tbody> <row> <entry>name</entry> - <entry>(string, optional), the name of your program, if not given - it will default to <varname>$argv[0]</varname></entry> + <entry>string</entry> + <entry>no, default to <varname>$argv[0]</varname> if not given</entry> + <entry>the name of your program, if not given</entry> </row> <row> <entry>description</entry> - <entry>(string optional), the description of your program: this - should explain what your program is supposed to do</entry> + <entry>string</entry> + <entry>no, but recommended for the help message</entry> + <entry>the description of your program: this should explain what + your program is supposed to do</entry> </row> <row> <entry>version</entry> - <entry>(string or numeric, optional), the program version number. - If not given, the --version option will not be available.</entry> + <entry>mixed (string or numeric)</entry> + <entry>no, note that if not given, the --version option will + not be available</entry> + <entry>the program version number</entry> </row> <row> <entry>add_help_option</entry> - <entry>(boolean, optional, default &true;), if set to &false;, tells - the parser to not generate automatically the - <quote>help</quote> option</entry> + <entry>boolean</entry> + <entry>no, default to &true;</entry> + <entry>if set to &false; the parser will not generate + automatically the <quote>help</quote> option</entry> </row> <row> <entry>add_version_option</entry> - <entry>(boolean, optional, default &true;), if set to &false;, tells - the parser to not generate automatically the - <quote>version</quote> option</entry> + <entry>boolean</entry> + <entry>no, default to &true;</entry> + <entry>if set to &false; the parser will not generate + automatically the <quote>version</quote> option</entry> </row> <row> <entry>force_posix</entry> - <entry>(boolean, optional, default &false;), if set to &true;, tells - the parser to force <acronym>POSIX</acronym> compliance (please see - the gettext manual for more information)</entry> + <entry>boolean</entry> + <entry>no, default to &false;</entry> + <entry>if set to &true;, the parser will force + <acronym>POSIX</acronym> compliance (please see the gettext + manual for more information)</entry> </row> </tbody> </tgroup> @@ -69,11 +86,13 @@ <title>The simplest way</title> <programlisting role="php"> <![CDATA[ +<?php require_once 'Console/CommandLine.php'; $parser = new Console_CommandLine(array( 'description' => 'A useful description for your program.', 'version' => '0.0.1', // the version of your program )); +?> ]]> </programlisting> </example> @@ -83,10 +102,12 @@ <title>Alternative method</title> <programlisting role="php"> <![CDATA[ +<?php require_once 'Console/CommandLine.php'; $parser = new Console_CommandLine(); $parser->description = 'A useful description for your program.'; $parser->version = '0.0.1'; // the version of your program +?> ]]> </programlisting> </example> @@ -115,10 +136,12 @@ <para> <example> <title>The <acronym>PHP</acronym> file</title> - <programlisting> + <programlisting role="php"> <![CDATA[ +<?php require_once 'Console/CommandLine.php'; $parser = Console_CommandLine::fromXmlFile('example.xml'); +?> ]]> </programlisting> </example> http://cvs.php.net/viewvc.cgi/peardoc/en/package/console/console-commandline/examples.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/console/console-commandline/examples.xml diff -u peardoc/en/package/console/console-commandline/examples.xml:1.1 peardoc/en/package/console/console-commandline/examples.xml:1.2 --- peardoc/en/package/console/console-commandline/examples.xml:1.1 Mon May 19 12:33:40 2008 +++ peardoc/en/package/console/console-commandline/examples.xml Mon May 19 13:54:12 2008 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.console.console-commandline.examples"> <refnamediv> <refname>Examples</refname> @@ -11,6 +11,7 @@ <title>Basic example</title> <programlisting role="php"> <![CDATA[ +<?php // Include the Console_CommandLine package. require_once 'Console/CommandLine.php'; @@ -63,6 +64,7 @@ } catch (Exception $exc) { $parser->displayError($exc->getMessage()); } +?> ]]> </programlisting> </example> @@ -110,6 +112,7 @@ <title>Basic example (<acronym>PHP</acronym> file)</title> <programlisting role="php"> <![CDATA[ +<?php // Include the Console_CommandLine package. require_once 'Console/CommandLine.php'; @@ -127,6 +130,7 @@ } catch (Exception $exc) { $parser->displayError($exc->getMessage()); } +?> ]]> </programlisting> </example> http://cvs.php.net/viewvc.cgi/peardoc/en/package/console/console-commandline/intro.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/console/console-commandline/intro.xml diff -u peardoc/en/package/console/console-commandline/intro.xml:1.1 peardoc/en/package/console/console-commandline/intro.xml:1.2 --- peardoc/en/package/console/console-commandline/intro.xml:1.1 Mon May 19 12:33:40 2008 +++ peardoc/en/package/console/console-commandline/intro.xml Mon May 19 13:54:12 2008 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.console.console-commandline.intro"> <refnamediv> <refname>Introduction</refname> @@ -20,8 +20,9 @@ help messages for you. </para> <para> - DISCLAIMER: since Console_CommandLine was highly inspired from the python - optparse module and thus is very similar to it, some parts of this document + DISCLAIMER: since Console_CommandLine was highly inspired from the + <ulink url="http://docs.python.org/lib/module-optparse.html">python + optparse module</ulink> and thus is very similar to it, some parts of this document were shamelessly copied from optparse manual. </para> <para> @@ -29,6 +30,7 @@ <title>A simple example:</title> <programlisting role="php"> <![CDATA[ +<?php require_once 'Console/CommandLine.php'; $parser = new Console_CommandLine(); @@ -55,6 +57,7 @@ } catch (Exception $exc) { $parser->displayError($exc->getMessage()); } +?> ]]> </programlisting> </example> http://cvs.php.net/viewvc.cgi/peardoc/en/package/console/console-commandline/populating-the-parser.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/package/console/console-commandline/populating-the-parser.xml diff -u peardoc/en/package/console/console-commandline/populating-the-parser.xml:1.1 peardoc/en/package/console/console-commandline/populating-the-parser.xml:1.2 --- peardoc/en/package/console/console-commandline/populating-the-parser.xml:1.1 Mon May 19 12:33:40 2008 +++ peardoc/en/package/console/console-commandline/populating-the-parser.xml Mon May 19 13:54:12 2008 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <refentry id="package.console.console-commandline.populating-the-parser"> <refnamediv> <refname>Populating the parser</refname> @@ -74,10 +74,12 @@ </itemizedlist> <table> <title>Available option parameters</title> - <tgroup cols="3"> + <tgroup cols="5"> <thead> <row> <entry>name</entry> + <entry>type</entry> + <entry>required</entry> <entry>description</entry> <entry>example</entry> </row> @@ -85,41 +87,51 @@ <tbody> <row> <entry>short_name</entry> - <entry>(string, required if no long_name given), the option short name</entry> + <entry>string</entry> + <entry>yes, if no long_name given</entry> + <entry>the option short name</entry> <entry>-o</entry> </row> <row> <entry>long_name</entry> - <entry>(string, required if no short_name given), the option long name</entry> + <entry>string</entry> + <entry>yes, if no short_name given</entry> + <entry>the option long name</entry> <entry>--orientation</entry> </row> <row> <entry>description</entry> - <entry>(string, optional, but recommended for the help message), - a description for the option</entry> + <entry>string</entry> + <entry>no, but recommended for the help message</entry> + <entry>a description for the option</entry> <entry>orientation of the page: ltr (default) or rtl</entry> </row> <row> <entry>action</entry> - <entry>(string, optional, default is <quote>StoreString</quote>), - the option action (see next section for details)</entry> + <entry>string</entry> + <entry>no, default to <quote>StoreString</quote></entry> + <entry>the option action (see next section for details)</entry> <entry>StoreString</entry> </row> <row> <entry>default</entry> - <entry>(mixed, optional), the option default value</entry> + <entry>mixed</entry> + <entry>no</entry> + <entry>the option default value</entry> <entry>ltr</entry> </row> <row> <entry>choices</entry> - <entry>(array, optional, only relevant for options that expect - argument(s)), an array of possible values for the option</entry> + <entry>array</entry> + <entry>no, only relevant for options that expect argument(s)</entry> + <entry>list of possible values for the option</entry> <entry>array('ltr', 'rtl')</entry> </row> <row> <entry>help_name</entry> - <entry>(string, optional, if not given it will default to the - option name) the name to display in the option help line</entry> + <entry>string</entry> + <entry>no, if not given it will default to the option name</entry> + <entry>the name to display in the option help line</entry> <entry>page_orientation (the help ligne will be: --orientation=page_orientation)</entry> </row> @@ -132,6 +144,7 @@ <title>Adding commandline options</title> <programlisting role="php"> <![CDATA[ +<?php require_once 'Console/CommandLine.php'; $parser = new Console_CommandLine(array( 'description' => 'A useful description for your program.', @@ -169,13 +182,14 @@ } catch (Exception $exc) { $parser->displayError($exc->getMessage()); } +?> ]]> </programlisting> </example> </para> <para>Now if the user type:</para> <para> - <programlisting> + <programlisting role="text"> <![CDATA[ $ <yourprogram> -vo rtl ]]> @@ -183,7 +197,7 @@ </para> <para>or (equivalent):</para> <para> - <programlisting> + <programlisting role="text"> <![CDATA[ $ <yourprogram> --verbose --orientation=rtl ]]> @@ -227,8 +241,10 @@ <para> <programlisting role="php"> <![CDATA[ +<?php $parser->addOption('verbose', array('short_name'=>'-v', 'action'=>'StoreTrue')); $result = $parser->parse(); +?> ]]> </programlisting> </para> @@ -248,8 +264,10 @@ <para> <programlisting role="php"> <![CDATA[ +<?php $parser->addOption('verbose', array('short_name'=>'-q', 'action'=>'StoreFalse')); $result = $parser->parse(); +?> ]]> </programlisting> </para> @@ -269,8 +287,10 @@ <para> <programlisting role="php"> <![CDATA[ +<?php $parser->addOption('outfile', array('short_name'=>'-o', 'action'=>'StoreString')); $result = $parser->parse(); +?> ]]> </programlisting> </para> @@ -289,8 +309,10 @@ <para> <programlisting role="php"> <![CDATA[ +<?php $parser->addOption('width', array('long_name'=>'--width', 'action'=>'StoreInt')); $result = $parser->parse(); +?> ]]> </programlisting> </para> @@ -309,8 +331,10 @@ <para> <programlisting role="php"> <![CDATA[ +<?php $parser->addOption('level', array('short_name'=>'-l', 'action'=>'StoreFloat')); $result = $parser->parse(); +?> ]]> </programlisting> </para> @@ -328,19 +352,21 @@ <programlisting role="text">$ &lt;yourprogram&gt; -v -v -v --verbose</programlisting> </para> <para> - will store the float the integer 4 in + will store the integer 4 in <varname>$result->options['verbose_level']</varname>, assuming the option was defined like this: </para> <para> <programlisting role="php"> <![CDATA[ +<?php $parser->addOption('verbose_level', array( 'short_name' => '-v', 'long_name' => '--verbose', 'action' => 'Counter' )); $result = $parser->parse(); +?> ]]> </programlisting> </para> @@ -366,8 +392,10 @@ <para> <programlisting role="php"> <![CDATA[ -$parser->addOption('level', array('short_name'=>'-l', 'action'=>'StoreFloat')); +<?php +$parser->addOption('password', array('short_name'=>'-p', 'action'=>'Password')); $result = $parser->parse(); +?> ]]> </programlisting> </para> @@ -449,10 +477,12 @@ <para> <table> <title>Available arguments parameters</title> - <tgroup cols="3"> + <tgroup cols="5"> <thead> <row> <entry>name</entry> + <entry>type</entry> + <entry>required</entry> <entry>description</entry> <entry>example</entry> </row> @@ -460,20 +490,23 @@ <tbody> <row> <entry>description</entry> - <entry>(string, optional, but recommended for the help message), - a description for the argument</entry> + <entry>string</entry> + <entry>no, but recommended for the help message</entry> + <entry>a description for the argument</entry> <entry>entry list of input files separated by spaces</entry> </row> <row> <entry>multiple</entry> - <entry>(boolean, optional, default to &false;), tells the - parser that the argument expects multiples values</entry> + <entry>boolean</entry> + <entry>no, default to &false;</entry> + <entry>tells the parser that the argument expects multiples values</entry> <entry>&true;</entry> </row> <row> <entry>help_name</entry> - <entry>(string, optional, if not given it will default to the - argument name), the name to display in the argument help line</entry> + <entry>string</entry> + <entry>no, if not given it will default to the argument name</entry> + <entry>the name to display in the argument help line</entry> <entry>files</entry> </row> </tbody> @@ -485,6 +518,7 @@ <title>Adding commandline arguments</title> <programlisting role="php"> <![CDATA[ +<?php require_once 'Console/CommandLine.php'; $parser = new Console_CommandLine(); @@ -500,15 +534,16 @@ } catch (Exception $exc) { $parser->displayError($exc->getMessage()); } +?> ]]> </programlisting> </example> </para> <para>If the user type:</para> <para> - <programlisting> + <programlisting role="text"> <![CDATA[ -<yourprogram> file1 file2 file3 +$ <yourprogram> file1 file2 file3 ]]> </programlisting> </para>
« previous php.pear.doc (#10786) next »