[commits] [Wiki] changed: Doc/Dev/HordeArgv

Jan Schneider jan at horde.org
Wed May 17 15:10:00 UTC 2017


jan  Wed, 17 May 2017 15:10:00 +0000

Modified page: https://wiki.horde.org/Doc/Dev/HordeArgv
New Revision:  3
Change log:  Fix syntax

@@ -138,26 +138,26 @@

  First, consider the verbose/quiet example. If we want //Horde_Argv//  
to set verbose to TRUE unless "-q" is seen, then we can do this:

  <code type="php">
-$parser->addOption('-v', array('action' => 'store_true', 'dest' =>  
'verbose', $default => true));
+$parser->addOption('-v', array('action' => 'store_true', 'dest' =>  
'verbose', 'default' => true));
  $parser->addOption('-q', array('action' => 'store_false', 'dest' =>  
'verbose'));
  </code>

  Oddly enough, this is exactly equivalent:

  <code type="php">
  $parser->addOption('-v', array('action' => 'store_true', 'dest' =>  
'verbose'));
-$parser->addOption('-q', array('action' => 'store_false', 'dest' =>  
'verbose', $default => true));
+$parser->addOption('-q', array('action' => 'store_false', 'dest' =>  
'verbose', 'default' => true));
  </code>

  Those are equivalent because you're supplying a default value for  
the option's destination, and these two options happen to have the  
same destination (the verbose variable).

  Consider this:

  <code type="php">
-$parser->addOption('-v', array('action' => 'store_true', 'dest' =>  
'verbose', $default => false));
-$parser->addOption('-q', array('action' => 'store_false', 'dest' =>  
'verbose', $default => true));
+$parser->addOption('-v', array('action' => 'store_true', 'dest' =>  
'verbose', 'default' => false));
+$parser->addOption('-q', array('action' => 'store_false', 'dest' =>  
'verbose', 'default' => true));
  </code>

  Again, the default value for verbose will be TRUE: the last default  
value supplied for any particular destination attribute is the one  
that counts.

@@ -179,9 +179,9 @@
  $usage = 'usage: %prog [options] arg1 arg2';
  $parser = new Horde_Argv_Parser(array('usage' => $usage));
  $parser->addOption(
      '-v', '--verbose',
-    array('action' => 'store_true', 'dest' => 'verbose', $default => 1,
+    array('action' => 'store_true', 'dest' => 'verbose', 'default' => 1,
            'help' => 'make lots of noise [default]')
  );
  $parser->addOption(
      '-q', '--quiet',



More information about the commits mailing list