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

Source for file example.php

Documentation is available at example.php

  1. <?php
  2. /**
  3.  * Example for Console_Getargs class
  4.  * 
  5.  * $Id: example.php,v 1.2 2004/09/20 09:27:34 mansion Exp $
  6.  */
  7.  
  8. require_once('Console/Getargs.php');
  9.  
  10. $config = array(
  11.             // Option takes 2 values
  12.             'files|images' => array('short' => 'f|i''min' => 2'max' => 2'desc' => 'Set the source and destination image files.'),
  13.             // Option takes 1 value
  14.             'width' => array('short' => 'w''min' => 1'max' => 1'desc' => 'Set the new width of the image.'),
  15.             // Option is a switch
  16.             'debug' => array('short' => 'd''max' => 0'desc' => 'Switch to debug mode.'),
  17.             // Option takes from 1 to 3 values, using the default value(s) if the arg is not present
  18.             'formats' => array('min' => 1'max' => 3'desc' => 'Set the image destination format.''default' => array('jpegbig''jpegsmall')),
  19.             // Option takes from 1 to an unlimited number of values
  20.             'filters' => array('short' => 'fi''min' => 1'max' => -1'desc' => 'Set the filters to be applied to the image upon conversion. The filters will be used in the order they are set.'),
  21.             // Option accept 1 value or nothing. If nothing, then the default value is used
  22.             'verbose' => array('short' => 'v''min' => 0'max' => 1'desc' => 'Set the verbose level.''default' => 3)
  23.             );
  24.  
  25. $args =Console_Getargs::factory($config);
  26.  
  27. if (PEAR::isError($args)) {
  28.     $header "Console_Getargs Example\n".
  29.               'Usage: '.basename($_SERVER['SCRIPT_NAME'])." [options]\n\n";
  30.     if ($args->getCode(=== CONSOLE_GETARGS_ERROR_USER{
  31.         echo Console_Getargs::getHelp($config$header$args->getMessage())."\n";
  32.     else if ($args->getCode(=== CONSOLE_GETARGS_HELP{
  33.         echo Console_Getargs::getHelp($config$header)."\n";
  34.     }
  35.     exit;
  36. }
  37.  
  38. echo 'Verbose: '.$args->getValue('verbose')."\n";
  39. echo 'Formats: '.(is_array($args->getValue('formats')) implode(', '$args->getValue('formats'))."\n" $args->getValue('formats')."\n");
  40. echo 'Files: '.($args->isDefined('files'implode(', '$args->getValue('files'))."\n" "undefined\n");
  41. if ($args->isDefined('fi')) {
  42.     echo 'Filters: '.(is_array($args->getValue('fi')) implode(', '$args->getValue('fi'))."\n" $args->getValue('fi')."\n");
  43. else {
  44.     echo "Filters: undefined\n";
  45. }
  46. echo 'Width: '.$args->getValue('w')."\n";
  47. echo 'Debug: '.($args->isDefined('d'"YES\n" "NO\n");
  48.  
  49. // Test with:
  50. // ----------
  51. // php -q example.php -h
  52. // php -q example.php -v -f src.tiff dest.tiff
  53. // php -q example.php -v5 -f src.tiff dest.tiff -d
  54. // php -q example.php -v 1 -f src.tiff dest.tiff -d --width=100
  55. // php -q example.php -v -f src.tiff dest.tiff -fi sharp blur
  56. // php -q example.php --format gif jpeg png
  57.  
  58. ?>

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