[commits] [Wiki] changed: Doc/Dev/HordeArgv
Jan Schneider
jan at horde.org
Mon Feb 4 16:52:30 UTC 2013
jan Mon, 04 Feb 2013 17:52:29 +0100
Modified page: http://wiki.horde.org/Doc/Dev/HordeArgv
New Revision: 2
Change log: Add links to further docs
@@ -52,9 +52,9 @@
This tutorial document only covers the four most important option
attributes: "action", "type", "dest" (destination), and "help". Of
these, "action" is the most fundamental.
+++ Option actions
-Actions tell //Horde_Argv// what to do when it encounters an option
on the command line. There is a fixed set of actions hard-coded into
//Horde_Argv//; adding new actions is an advanced topic covered in
Extending //Horde_Argv//. Most actions tell //Horde_Argv// to store a
value in some variable -- for example, take a string from the command
line and store it in an attribute of options.
+Actions tell //Horde_Argv// what to do when it encounters an option
on the command line. There is a fixed set of actions hard-coded into
//Horde_Argv//; adding new actions is an advanced topic covered in
((Doc/Dev/HordeArgvExtend|Extending Horde_Argv)). Most actions tell
//Horde_Argv// to store a value in some variable -- for example, take
a string from the command line and store it in an attribute of options.
If you don't specify an option action, //Horde_Argv// defaults to "store".
++++ The store action
@@ -76,9 +76,9 @@
$args = array('-f', 'foo.txt');
list($values, $args) = $parser->parseArgs(args);
</code>
-When //Horde_Argv// sees the "-f", it consumes the next argument,
"foo.txt", and stores it in $values->filename, where values is the
first return value from {{parseArgs()}}. So, after this call to
{{parseArgs()}}, $values->filename is "foo.txt".
+When //Horde_Argv// sees the "-f", it consumes the next argument,
"foo.txt", and stores it in $values->filename, where values is the
first return value from {{parseArgs()}}. So, after this call to
{{parseArgs()}}, {{$values->filename}} is "foo.txt".
Some other option types supported by //Horde_Argv// are "int" and
"float". Here's an option that expects an integer argument:
<code type="php">
@@ -129,9 +129,9 @@
: "append" : append this option's argument to a list
: "count" : increment a counter by one
: "callback" : call a specified function
-These are covered in the Advanced Usage and Option Callbacks documents.
+These are covered in the ((Doc/Dev/HordeArgvAdvanced|Advanced Usage))
and ((Doc/Dev/HordeArgvCallbacks|Option Callbacks)) documents.
+++ Default values
All of the above examples involve setting some variable (the
"destination") when certain command-line options are seen. What
happens if those options are never seen? Since we didn't supply any
defaults, they are all set to NULL. Usually, this is just fine, but
sometimes you want more control. To address that need, //Horde_Argv//
lets you supply a default value for each destination, which is
assigned before the command-line is parsed.
More information about the commits
mailing list