Console_CommandLine
[ class tree: Console_CommandLine ] [ index: Console_CommandLine ] [ all elements ]

example

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * This file is part of the PEAR Console_CommandLine package.
  7.  *
  8.  * A simple example demonstrating the basic features of the Console_CommandLine
  9.  * package.
  10.  * In this example we create a program that simply zip a set of files.
  11.  *
  12.  * PHP version 5
  13.  *
  14.  * LICENSE: This source file is subject to the MIT license that is available
  15.  * through the world-wide-web at the following URI:
  16.  * http://opensource.org/licenses/mit-license.php
  17.  *
  18.  * @category  Console
  19.  * @package   Console_CommandLine
  20.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  21.  * @copyright 2007 David JEAN LOUIS
  22.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  23.  * @version   CVS: $Id: ex1.php,v 1.1 2007/12/17 08:25:33 izi Exp $
  24.  * @link      http://pear.php.net/package/Console_CommandLine
  25.  * @since     File available since release 0.1.0
  26.  */
  27.  
  28. // Include the Console_CommandLine package.
  29. require_once 'Console/CommandLine.php';
  30.  
  31. // create the parser
  32. $parser = new Console_CommandLine(array(
  33.     'description' => 'zip given files using the php zip module.',
  34.     'version'     => '1.0.0'
  35. ));
  36.  
  37. // add an option to make the program verbose
  38. $parser->addOption('verbose'array(
  39.     'short_name'  => '-v',
  40.     'long_name'   => '--verbose',
  41.     'action'      => 'StoreTrue',
  42.     'description' => 'turn on verbose output'
  43. ));
  44.  
  45. // add an option to delete original files after zipping
  46. $parser->addOption('delete'array(
  47.     'short_name'  => '-d',
  48.     'long_name'   => '--delete',
  49.     'action'      => 'StoreString',
  50.     'description' => 'delete original files after zip operation',
  51.     'choices'     => array('foo''bar')
  52. ));
  53.  
  54. // add the files argument, the user can specify one or several files
  55. $parser->addArgument('files'array(
  56.     'multiple' => true,
  57.     'description' => 'list of files to zip separated by spaces'
  58. ));
  59.  
  60. // add the zip file name argument
  61. $parser->addArgument('zipfile'array('description' => 'zip file name'));
  62.  
  63. // run the parser
  64. try {
  65.     $result $parser->parse();
  66.     // write your program here...
  67.     print_r($result->options);
  68.     print_r($result->args);
  69. catch (Exception $exc{
  70.     $parser->displayError($exc->getMessage());
  71. }
  72.  
  73. ?>

Documentation generated on Mon, 11 Mar 2019 15:13:13 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.