comparison vendor/pear/console_commandline/docs/examples/ex1.php @ 0:1e000243b222

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:50:29 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e000243b222
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$
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 'add_list_option' => true
53 ));
54
55 // add the files argument, the user can specify one or several files
56 $parser->addArgument('files', array(
57 'multiple' => true,
58 'description' => 'list of files to zip separated by spaces'
59 ));
60
61 // add the zip file name argument
62 $parser->addArgument('zipfile', array('description' => 'zip file name'));
63
64 // run the parser
65 try {
66 $result = $parser->parse();
67 // write your program here...
68 print_r($result->options);
69 print_r($result->args);
70 } catch (Exception $exc) {
71 $parser->displayError($exc->getMessage());
72 }
73
74 ?>