OSDN Git Service

- deleted needless command line option.
[ethna/ethna.git] / class / Plugin / Handle / CreatePlugin.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  CreatePlugin.php
5  *
6  *  please go to http://ethna.jp/ethna-document-dev_guide-pearchannel.html
7  *  for more info.
8  *
9  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
10  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
11  *  @package    Ethna
12  *  @version    $Id$
13  */
14
15 // {{{ Ethna_Plugin_Handle_CreatePlugin
16 /**
17  *  create Ethna Plugin Skelton handler.
18  *
19  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
20  *  @access     public
21  *  @package    Ethna
22  */
23 class Ethna_Plugin_Handle_CreatePlugin extends Ethna_Plugin_Handle
24 {
25     // {{{ perform()
26     /**
27      * @access public
28      */
29     function perform()
30     {
31         $r =& $this->_getopt(
32             array(
33                 'basedir=',
34                 'type=',
35                 'plugin-package',
36             )
37         ); 
38         if (Ethna::isError($r)) {
39             return $r;
40         }
41         list($opt_list, $arg_list) = $r;
42
43         //  plugin name
44         $plugin_name = array_shift($arg_list);
45         if (empty($plugin_name)) {
46             return Ethna::raiseError('Please specify plugin Name.', 'usage');
47         }
48
49         //  plugin types
50         $type = end($opt_list['type']);
51         $types = explode(',', $type);
52         if (empty($type)) {
53             $types = array('v', 'f', 'sm'); // Validator, Filter, Smarty modifier.
54         } 
55
56         //  basedir
57         if (isset($opt_list['basedir'])) {
58             $basedir = realpath(end($opt_list['basedir']));
59         } else {
60             $basedir = getcwd();
61         }
62
63         //  no-ini file flag.
64         $forpackage = (isset($opt_list['plugin-package'])) ? true : false; 
65
66         $r = Ethna_Generator::generate('CreatePlugin', NULL, $basedir, $types, $forpackage, $plugin_name);
67         if (Ethna::isError($r)) {
68             printf("error occurred while generating plugin skelton. please see also error messages given above\n\n");
69             return $r;
70         }
71         printf("\nplugin skelton for [%s] is successfully generated.\n\n", $plugin_name);
72         return true;
73     }
74     // }}}
75
76     // {{{ getDescription()
77     /**
78      *  @access public
79      */
80     function getUsage()
81     {
82         return <<<EOS
83 ethna {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-p|--plugin-package] plugin-name
84     -t: type is as follows (separated by comma):
85         f = Filter (default),
86         v = Validator (default),
87         sm = Smarty modifier (default)
88         sb = Smarty block,
89         sf = Smarty function,
90     -p: if you want to make plugin package, set this option.
91 EOS;
92     }
93     // }}}
94
95     // {{{ getDescription()
96     /**
97      *  @access public
98      */
99     function getDescription()
100     {
101         return <<<EOS
102 make plugin package:
103     {$this->id} [-b|--basedir=dir] [-t|--type=f,v,sb,sf,sm...] [-p|--plugin-package] plugin-name
104 EOS;
105     }
106     // }}}
107 }
108 // }}}
109 ?>