root/modules/branches/2.10/package.php

Revision 13482, 20.7 kB (checked in by mbrevda, 1 year ago)

upstream changes - add hookable templates so that any module can offer templates for backups

  • Property svn:executable set to *
Line 
1 #!/usr/bin/php -q
2 <?php
3 /**
4  * Copyright 2011 by Schmooze Com., Inc.
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * @author mbrevda => gmail ! com
16  *
17  * options:
18  *    run with --help for options
19  *
20  */
21
22 //get cli opts
23 $longopts = array(
24     'bump::',
25     'checkphp::',
26     'debug::',
27     'help::',
28     'log::',
29     'module:',
30     'msg::',
31     're::',
32     'verbose::'
33 );
34 $vars = getopt('m:d::L::v::c::', $longopts);
35
36
37 if (isset($vars['d']) || isset($vars['L'])) {
38     echo package_show_help(true);
39     sleep(3);
40 }
41
42 //set up some other settings
43 $vars['rver']         = '2.10';
44 $vars['fwbranch']     = 'branches/2.10';
45 $vars['fw']            = 'framework';
46 $vars['fw_ari']        = 'fw_ari';
47 $vars['fw_lang']    = 'fw_langpacks';
48 $vars['svn_path']    = 'http://svn.freepbx.org';
49 $vars['rm_files']    = array(); //files that will be deleted after the script completes
50 $vars['php_-l']        = 'php -l';
51 $vars['php_extens']    = array('php', 'agi'); //extens to be considered as php for syntax checking
52 $final_status        = array();//status message to be printed after script is run
53
54 //move cli args to longopts for clarity throught the script
55 //note: once we depend on 5.3, we can refactor this so that either short
56 //or long work. For now, short will overwrite the long
57 //print_r($vars);
58 if (isset($vars['m'])) {
59     $vars['module'] = (array) $vars['m'];
60     sort($vars['module']);
61     unset($vars['m']);
62 } elseif(isset($vars['module'])) {
63     $vars['module'] = (array) $vars['module'];
64     sort($vars['module']);
65 } else {
66     $vars['module'] = false;
67 }
68
69 //set all modules if --modules was set to *
70 if (isset($vars['module']) && is_array($vars['module']) && in_array('*', $vars['module'])) {
71     $vars['module'] = array();
72     $ls = scandir(dirname(__FILE__));
73     foreach($ls as $item) {
74         if (strpos($item, '.') !== 0 && is_dir($item)) {
75             $vars['module'][] = $item;
76         }
77     }
78     sort($vars['module']);
79 }
80
81 if (isset($vars['bump']) && $vars['bump'] != 'false') {
82     $vars['bump'] = ctype_digit($vars['bump']) ? $vars['bump'] : true;
83 } else {
84     $vars['bump'] = false;
85 }
86
87 if (isset($vars['d'])) {
88     $vars['debug'] = true;
89     unset($vars['d']);
90 } elseif (isset($vars['debug']) && $vars['debug'] != 'false') {
91     $vars['debug'] = true;
92 } else {
93     $vars['debug'] = false;
94 }
95
96 if (isset($vars['help']) && $vars['help'] != 'help') {
97     $vars['help'] = true;
98 } else {
99     $vars['help'] = false;
100 }
101
102 if (isset($vars['L'])) {
103     $vars['checkphp'] = false;
104     unset($vars['L']);
105 } elseif (!isset($vars['checkphp']) || isset($vars['checkphp']) && $vars['checkphp'] != 'false') {
106     $vars['checkphp'] = true;
107 }
108
109 if (isset($vars['log']) && $vars['log'] != 'log') {
110     $vars['log'] = true;
111 } else {
112     $vars['log'] = false;
113 }
114
115 if (isset($vars['v'])) {
116     $vars['verbose'] = true;
117     unset($vars['L']);
118 } elseif (isset($vars['verbose']) && $vars['verbose'] != 'false') {
119     $vars['verbose'] = true;
120 } else {
121     $vars['verbose'] = false;
122 }
123
124 $vars['svn_q'] = $vars['debug'] || $vars['verbose'] ? '' : ' --quiet ';
125 //set re
126 //move re to an array if there are commas as part of the value
127 if (isset($vars['re'])) {
128     switch (true) {
129         case is_array($vars['re']):
130             foreach ($vars['re'] as $k => $v) {
131                 if ($v) {
132                     $vars['re'][$k] = '#' . preg_replace("/[^0-9]/", '', $v);
133                 }
134             }
135     
136             $vars['re'] = 're ' . implode(', ', $vars['re']) . ' ';
137             break;
138         case is_string($vars['re']):
139             $vars['re'] = 're #' . preg_replace("/[^0-9]/", '', $vars['re']) . ' ';
140             break;
141         default:
142             break;
143     }
144 } else {
145     $vars['re'] = '';
146 }
147
148 $vars['msg'] = isset($vars['msg']) ? trim($vars['msg']) . ' ' : '';
149 $vars['msg'] = $vars['re'] ? $vars['re'] . '- ' . $vars['msg'] : $vars['msg'];
150
151 if (isset($vars['c'])) {
152     echo 'Username: ';
153     $vars['username'] = trim(shell_exec('read -afoo; echo $foo'));
154     if (!$vars['username']) {
155         echo 'invalid username';
156         exit(1);
157     }
158     
159     echo 'Password: ';
160     $vars['password'] = trim(shell_exec('read -s -afoo; echo $foo'));
161     if (!$vars['password']) {
162         echo 'invalid password';
163         exit(1);
164     }
165     
166     //c = credentials
167     $vars['svn_c'] = ' --username ' . $vars['username']
168                     . ' --password ' . $vars['password'] . ' ';
169 } else {
170     $vars['svn_c'] = '';
171 }
172
173 //if help was requested, show help and exit
174 if ($vars['help']) {
175     echo package_show_help();
176     exit();
177 }
178 //ensure we have modules to package
179 if (!$vars['module']) {
180     die("No modules specified. Please specify at least one module" . PHP_EOL);
181     echo package_show_help();
182     exit();
183 }
184
185 /*
186  * FreePBX supports devlopment with a file structure basically as followes:
187  * framework/
188  *            ...
189  *            admin/
190  *                modules/ <--- svn switch'ed to the modules directory
191  *
192  * modules/
193  *        branches/
194  *            ...
195  *
196  * While we can checkin and package a module from either directory, we can only
197  * check in tarballs to modules/release/...
198  * Here we attempt to auto-detect the release/ directory, and fail if we can't find it
199  * NOTE: you still need to have the entire freepbx shebang in place to check in modules!
200  */
201 if (is_dir('../../release/')) {//modules directory
202     $vars['reldir'] = '../../release/' . $vars['rver'];
203 } elseif(is_dir('../../../../../../modules/release/')) {//trunk
204         $vars['reldir'] = '../../../../../../modules/release/' . $vars['rver'];
205 } elseif(is_dir('../../../../../../../modules/release/')) {//framewokr branches
206     $vars['reldir'] = '../../../../../../../modules/release/' . $vars['rver'];
207 } else {
208     echo 'FATAL: release directory not found!' . PHP_EOL;
209     exit();
210 }
211 //print_r($vars);exit();
212
213 //ensure the module and release directorys are up to date
214 echo 'Updating svn...' . PHP_EOL;
215 run_cmd('svn up ' . $vars['svn_c'] . $vars['svn_q'] . $vars['reldir'] . ' . ');
216
217 foreach ($vars['module'] as $mod) {
218     $mod         = trim($mod, '/');
219     $mod_dir    = dirname(__FILE__) . '/' . $mod;
220     $tar_dir    = $mod_dir;
221     //files/dirs to be excluded from tar
222     $exclude    = array();
223     //argument to find for additional files/dirs to be excluded from tar
224     $exclude_find_arg = '\( -iname ".*" ! -iname ".htaccess" \)';
225     $files         =
226     $filename    =
227     $md5        =
228     $xml         =
229     $rawname    =
230     $ver         =
231     $x            = '';
232     $file_scan_exclude_list = array();
233     
234     
235     echo 'Packaging ' . $mod . '...' . PHP_EOL;
236     if (!file_exists($mod_dir . '/module.xml')) {
237         echo $mod_dir . '/module.xml dose not exists, ' . $mod . ' will not be built!' . PHP_EOL;
238         continue;
239     }
240
241     //test xml file and get some of its values
242     list($rawname, $ver) = check_xml($mod);
243     
244     //dont conitunue if there is an issue with the xml
245     if ($rawname == false || $ver == false) {
246         continue;
247     }
248     // Run xml script through the exact method that FreePBX currently uses. There have
249     // been cases where XML is valid but this method still fails so it won't be caught
250     // with the proper XML checer, better here then breaking the online repository
251     //
252     include_once('xml2Array.class.php');
253     $parser = new xml2ModuleArray($xml);
254     $xmlarray = $parser->parseAdvanced(file_get_contents($mod_dir . '/module.xml'));
255
256     //bump version if requested, and reset $ver
257     if ($vars['bump']) {
258         package_bump_version($mod, $vars['bump']);
259         //test xml file and get some of its values
260         list($rawname, $ver) = check_xml($mod);
261         $vars['log'] = true;
262     }
263     
264     //add changelog if requested
265     if ($vars['log']) {
266         $msg = $vars['msg'] ? $vars['msg'] : 'Packaging of ver ' . $ver;
267         package_update_changelog($mod, $msg);
268     }
269     
270     //include module specifc hook, if present
271     if (file_exists($mod_dir . '/' . 'package_hook.php')) {
272         if ($vars['debug'] || $vars['verbose']) {
273             echo 'Running ' . $mod_dir . '/' . 'package_hook.php...' . PHP_EOL;
274         }
275         
276         //test include so that includes can return false and prevent further execution if it fail
277         if (!include($mod_dir . '/' . 'package_hook.php')) {
278             $final_status[$mod] = '[FATAL] retrurned from ' . $mod_dir . '/' . 'package_hook.php with an error, '
279                 . $mod . ' wont be built' . PHP_EOL;
280             echo $final_status[$mod];
281             continue;
282         }
283     }
284     
285     //include any global hooks, if present
286     if (file_exists('package_hook.php')) {
287         if ($vars['debug'] || $vars['verbose']) {
288             echo 'Running ' . 'package_hook.php...' . PHP_EOL;
289         }
290         
291         //test include so that includes can return false and prevent further execution if it fail
292         if (!include('package_hook.php')) {
293             $final_status[$mod] = '[FATAL] retrurned from  package_hook.php with an error, '
294                 . $mod . ' wont be built' . PHP_EOL;
295              echo $final_status[$mod];
296             continue;
297         }
298     }
299     
300     //test xml file and get some of its values. We did this before, but the hooks
301     //may have changed something
302     list($rawname, $ver) = check_xml($mod);
303     
304     //dont conitunue if there is an issue with the xml
305     if ($rawname == false || $ver == false) {
306         continue;
307     }
308     
309     //check php files for syntax errors if requested
310     if ($vars['checkphp']) {   
311         //get list of files
312         $files = package_scandirr($tar_dir, true, $file_scan_exclude_list);
313         foreach ($files as $f) {
314             if (in_array(pathinfo($f, PATHINFO_EXTENSION), $vars['php_extens'])) {
315                 if (!run_cmd($vars['php_-l'] . ' ' . $f, $outline, (!$vars['debug'] && !$vars['verbose']), true)) {
316                     //add errors to array
317                     $syntaxt_errors[] = 'syntax error detected in ' . $f . ', ' $mod . ' won\'t be packaged' . PHP_EOL;
318                 }
319             }
320         }
321         unset($files, $list);
322         
323         if (isset($syntaxt_errors)) {
324             $final_status[$mod] = implode(PHP_EOL, $syntaxt_errors);
325             echo $final_status[$mod];
326             continue;
327         }
328     }
329
330     
331     //check in any out standing files
332     run_cmd('svn ci '
333             . $vars['svn_c']
334             . $vars['svn_q']
335             . '-m "[Auto Checking in outstanding changes in '
336             . $mod . '] ' . $vars['msg'] . '" ' . $mod_dir);
337
338     
339     //set tarball name var
340     $filename = $rawname . '-' . $ver . '.tgz';
341     
342     //add to exclude array, all '.*' except .htaccess
343     $exclude_raw = array();
344     exec('find ' . $mod_dir . ' ' $exclude_find_arg , $exclude_raw, $ret);
345
346     if ($ret) {
347         die("something went wrong with fund command looking for .* files to exclude");
348     }
349     foreach ($exclude_raw as $name) {
350         $exclude[] = basename($name);
351     }
352     $exclude = array_unique($exclude);
353     if ($vars['verbose'] || $vars['debug']) {
354         echo "excluding patterns:\n";
355         //print_r($exclude);
356     }
357
358     //build tarball
359     foreach ($exclude as $ex) {
360         $x .= ' --exclude="' . $ex . '"';
361     }
362
363     //if our tar path isnt were we currently are now (i.e. one level up from the module ot be packaged)
364     //tell tar to change directoires (-C) to one level above
365     $tar_dir_path   = explode('/', trim($tar_dir, '/'));
366     $tar_dir        = (is_array($tar_dir_path) && (count($tar_dir_path) > 1))? array_pop($tar_dir_path) : $mod_dir;
367     $tar_dir_path   = (is_array($tar_dir_path) && (count($tar_dir_path) > 1))
368                     ? ' -C /' . implode('/', $tar_dir_path) : '';
369     run_cmd('tar zcf ' . $filename . ' ' . $x . ' ' . $tar_dir_path . ' ' . $tar_dir);
370     
371     //update md5 sum
372     $module_xml = file_get_contents($mod_dir . '/' . 'module.xml');
373     if(file_exists($filename)) {
374         $md5 = md5_file($filename);
375         $module_xml = preg_replace('/<md5sum>(.*)<\/md5sum>/i','<md5sum>'.$md5.'</md5sum>',$module_xml);
376     } else {
377         echo "No Tarball Package found (in debug mode?)" . PHP_EOL;
378     }
379     
380     //update location
381     if(file_exists($filename)) {
382         $module_xml = preg_replace('/<location>(.*)<\/location>/i','<location>release/' . $vars['rver'] . '/' . $filename . '</location>',$module_xml);
383     }
384
385     file_put_contents($mod_dir . '/' . 'module.xml', $module_xml);
386
387     
388     //move tarbal to relase dir
389     run_cmd('mv ' . $filename . ' ' . $vars['reldir'] . '/');
390     
391     //add tarball to release repository
392     run_cmd('svn add ' . $vars['reldir'] . '/' . $filename . ' ' . $vars['svn_q']);
393     
394     //set mimetype of tarball
395     run_cmd('svn ps svn:mime-type application/tgz '
396             . $vars['reldir'] . '/' . $filename
397             . ' ' . $vars['svn_q'] . $vars['svn_c']);
398     
399     //check in tarball
400     run_cmd('svn ci '
401             . $vars['svn_c']
402             . $vars['svn_q']
403             . $vars['reldir'] . '/' . $filename
404             . ' -m"[Module package script: ' . $rawname . ' ' . $ver . '] '
405             . $vars['msg'] . '"');
406                     
407     //lastpublished seems to be off, let's make sure we svn up before extracting the
408     //revision just in case something above has pushed it out
409     run_cmd('svn up ' . $vars['svn_q'] . $vars['svn_c']
410             . $vars['reldir'] . '/' . $filename . ' ' . $mod_dir);
411     
412     
413     //set latpublished property
414     run_cmd('svn ps lastpublish ' . $vars['svn_q'] . $vars['svn_c']
415             . '`svn info '
416                 . $vars['svn_c'] . $mod_dir
417                 . ' | grep Revision: | awk \'{print $2}\'`'
418             . ' ' . $mod_dir);
419     
420     // appears we need to do an svn up here or it fails, maybe because of the propset above?
421     //TODO: see if this can be avoided
422     run_cmd('svn up '
423             . $vars['svn_c']
424             . $vars['svn_q']
425             . $vars['reldir'] . '/' . $filename . ' ' . $mod_dir);
426
427     //check in new module.xml
428     run_cmd('svn ci '
429             . $vars['svn_c']
430             . $vars['svn_q'] . $mod_dir
431             . ' -m"[Module package script: ' . $rawname . ' ' . $ver . '] '
432             . $vars['msg'] . '"');
433     
434     //cleanup any remaining files
435     foreach($vars['rm_files'] as $f) {
436         if (file_exists($f)) {
437             run_cmd('rm -rf ' . $f);
438         }
439     }
440     $final_status[$mod] = $mod . ' version ' . $ver
441                         . ' has been sucsessfuly packaged!' . PHP_EOL;
442     echo PHP_EOL . $final_status[$mod];
443     
444 }
445
446 //print report
447 echo PHP_EOL . PHP_EOL . PHP_EOL;
448 echo 'Package Script Report:' . PHP_EOL;
449 echo '---------------------' . PHP_EOL;
450 foreach ($final_status as $mod => $status) {
451     echo $status;
452 }
453
454 /**
455  * function package_scandirr
456  * scans a directory just like scandir(), only recursively
457  * returns a hierarchical array representing the directory structure
458  *
459  * @pram string - directory to scan
460  * @pram string - return absolute paths
461  * @pram array - list of excluded files/directories to ignore
462  * @returns array
463  *
464  * @author Moshe Brevda mbrevda => gmail ~ com
465  */
466 function package_scandirr($dir, $absolute = false, $exclude_list=array()) {
467     $list = array();
468     if ($absolute) {
469         global $list;
470     }
471     
472     
473     //get directory contents
474     if (!empty($exclude_list) && in_array(basename($dir), $exclude_list)) {
475         return $list;
476     }
477     foreach (scandir($dir) as $d) {
478         
479         //ignore any of the files in the array
480         if (in_array($d, array('.', '..', '.svn')) || (!empty($exclude_list) && in_array($d, $exclude_list))) {
481             continue;
482         }
483         
484         //if current file ($d) is a directory, call package_scandirr
485         if (is_dir($dir . '/' . $d)) {
486             if ($absolute) {
487                 package_scandirr($dir . '/' . $d, $absolute, $exclude_list);
488             } else {
489                 $list[$d] = package_scandirr($dir . '/' . $d, $absolute, $exclude_list);
490             }
491             
492         
493             //otherwise, add the file to the list
494         } elseif (is_file($dir . '/' . $d) || is_link($dir . '/' . $d)) {
495             if ($absolute) {
496                 $list[] = $dir . '/' . $d;
497             } else {
498                 $list[] = $d;
499             }
500         }
501     }
502
503     return $list;
504 }
505
506 //auto-bump module version, bumps last part by defualt
507 function package_bump_version($mod, $pos = '') {
508     global $mod_dir, $vars;
509     $xml = simplexml_load_file($mod_dir . '/module.xml');
510     $ver = explode('.', (string) $xml->version);
511     
512     //if $pos === true, reset it
513     if ($pos === true) {
514         $pos = '';
515     }
516     //pick last part if requested part isn't found
517     if (!isset($ver[$pos - 1])) {
518         $pos = count($ver);   
519     }
520     $pos = $pos - 1; //array start at 0, but people will count from 1.
521
522     //if we have only digits in this part, add 1
523     if (ctype_digit($ver[$pos])) {
524         $ver[$pos] = $ver[$pos] + 1;
525     } else {//find last groupe of digits and +1 them
526         $num = preg_split('/[0-9]+$/', $ver[$pos], 1);
527         $replace = strrpos($ver[$pos], $num);
528         $num = $num[0] + 1;
529         $ver[$pos] = substr($ver[$pos], 0, $replace -1) . $num;
530     }
531     
532     if ($vars['verbose']) {
533         echo 'Bumping ' . $mod . 's verison to ' . implode('.', $ver) . PHP_EOL;
534     }
535     
536     $xml->version = implode('.', $ver);
537     
538     //simplexml adds a xml decleration that freepbx doesnt like. Remove it.
539     $xml = trim(preg_replace('/^\<\?xml.*?\?\>/', '', $xml->asXML()));
540
541     if ($vars['debug'] || $vars['verbose']) {
542         echo 'Writing to ' . $mod_dir . '/module.xml :' . PHP_EOL;
543         echo $xml;
544     }
545     if (!$vars['debug']) {
546         file_put_contents($mod_dir . '/module.xml', $xml);
547     }
548
549     return true;
550 }
551
552 //update module's changelog
553 function package_update_changelog($mod, $msg) {
554     global $mod_dir, $vars, $ver;
555     $xml = simplexml_load_file($mod_dir . '/module.xml');
556     $log = explode("\n", (string) $xml->changelog);
557     
558     //firt element is ususally blank, remove it
559     array_shift($log);
560     
561     //prune to last 5 entreis
562     /* If pruning is to be added it should be configurable, please leave unless making that change
563      * as Bryan suggested, we may want to have it auto-prune comments from previous versions though
564      *
565     $log = array_slice($log, 0, 4);
566      */
567     
568     //if the current message is already the last, dont duplicate it
569     if ($log[0] == $ver . ' ' . $msg) {
570         if ($vars['verbose'] || $vars['debug']) {
571             echo 'No need to update changelag - last entry matches proposed entry';
572             return true;
573         }
574     }
575     
576     //add new mesage
577     array_unshift($log, '*' . $ver . '*' . ' ' . $msg);
578
579     
580     if ($vars['verbose']) {
581         echo 'Adding to ' . $mod . 's changelog: ' . $ver . ' ' . $msg;
582     }
583     
584     //fold changelog array back in to xml
585     $xml->changelog = "\n\t\t" . trim(implode("\n", $log)) . "\n\t";
586     
587     if ($vars['verbose']) {
588         echo 'Writing to ' . $mod_dir . '/module.xml :' . PHP_EOL;
589     }
590     
591     //simplexml adds a xml decleration that freepbx doesnt like. Remove it.
592     $xml = trim(preg_replace('/^\<\?xml.*?\?\>/', '', $xml->asXML()));
593     
594     if ($vars['debug']) {
595         echo 'Writing to ' . $mod_dir . '/module.xml :' . PHP_EOL;
596         echo $xml;
597     }
598     
599     if (!$vars['debug']) {
600         file_put_contents($mod_dir . '/module.xml', $xml);
601     }
602
603     return true;
604 }
605
606 // if $duplex set to true and in debug mode, it will echo the command AND run it
607 function run_cmd($cmd, &$outline='', $quiet = false, $duplex = false) {
608     global $vars;
609     $quiet = $quiet ? ' > /dev/null' : '';
610
611     if ($vars['debug']) {
612         echo $cmd . PHP_EOL;
613         if (!$duplex) {
614             return true;
615         }
616     }
617     if ($vars['verbose']) {
618         $bt = debug_backtrace();
619         echo PHP_EOL . '+' . $bt[0]["file"] . ':' . $bt[0]["line"] . PHP_EOL;
620         echo "\t" . $cmd . PHP_EOL;
621         $outline = system($cmd . $quiet, $ret_val);
622     } else {
623         $outline = system($cmd . $quiet, $ret_val);
624     }
625     return ($ret_val == 0);
626 }
627
628 //test xml file for validity and extract some info from it
629 function check_xml($mod) {
630     global $mod_dir;
631     //check the xml script integrity
632     $xml = simplexml_load_file($mod_dir . '/' . 'module.xml');
633     if($xml === FALSE) {
634         echo $mod_dir . '/module.xml seems corrupt, ' . $mod . ' won\'t be packaged' . PHP_EOL;
635         return array(false, false);
636     }
637     
638     //check that module name is set in module.xml
639     $rawname = (string) $xml->rawname;
640     if (!$rawname) {
641         echo $mod_dir . '/module.xml is missing a module name, ' . $mod . ' won\'t be packaged' . PHP_EOL;
642         $rawname = false;
643     }
644     
645     //check that module version is set in module.xml
646     $version = (string) $xml->version;
647     if (!$version) {
648         echo $mod_dir . '/module.xml is missing a version number, ' . $mod . ' won\'t be packaged' . PHP_EOL;
649         $version = false;
650     }
651
652     return array($rawname, $version);
653 }
654
655 //show help menu
656 function package_show_help($short = false) {
657     $final = '';
658     $ret[] = 'Package.php';
659     $ret[] = '-----------';
660     $ret[] = '';
661     if ($short) {
662         $ret[] = 'SHORT OPS HAVE BEEN DEPRICATED - PLEASE USE ONLY LONG OPTS!';
663     }
664     $ret[] = 'Short options MUST come after all the long options, or the long options will be ignored';
665     $ret[] = '';
666     
667     //args
668     $ret[] = array('--bump', 'Bump a modules version. You can specify the "octet" by adding a position '
669                 . 'I.e. --bump=2 will turn 3.4.5.6 in to 3.5.5.6. Leaving the position blank will bump the last "octet"');
670     $ret[] = array('--debug=false', 'Debug only - just run through the command but don\'t make any changes');
671     $ret[] = array('--checkphp=true', 'Run PHP syntaxt check on php files (php -l <file name>)');
672     $ret[] = array('-c', 'Prompt for svn credentials to be used for all svn calls');
673     $ret[] = array('--help', 'Show this menu and exit');
674     $ret[] = array('--log', 'Update module.xml\'s changelog.');
675     $ret[] = array('--module', 'Module to be packaged. You can use one module per --module argument (for multiples), or * for all');
676     $ret[] = array('--msg', 'Optional commit message.');
677     $ret[] = array('--re', 'A ticket number to be referenced in all checkins (i.e. "re #627...")');
678     $ret[] = array('--verbose', 'Run with extra verbosity and print each command before it\'s executed');
679     
680     $ret[] = '';
681     
682     //generate formated help message
683     foreach ($ret as $r) {
684         if (is_array($r)) {
685             //pad the option
686             $option = '  ' . str_pad($r[0], 20);
687             
688             //explode the definition to manageable chunks
689             $def = explode('§', wordwrap($r[1], 55, "§", true));
690             
691             //and pad the def with whitespace 20 chars to the left stating from the second line
692             if (count($def) > 1) {
693                 $first = array_shift($def);
694                 foreach ($def as $my => $item) {
695                     $def[$my] = str_pad('', 22) . $item . PHP_EOL;
696                 }
697             } elseif (count($def) == 1) {
698                 $first = implode($def);
699                 $def = array();
700             } else {
701                 $first = '';
702                 $def = array();
703             }
704             
705             $definition = $first . PHP_EOL . implode($def);
706             $final .= $option . $definition;
707         } else {
708             $final .=  $r . PHP_EOL;
709         }
710     }
711     return $final;
712 }
713 ?>
714
Note: See TracBrowser for help on using the browser.