[ Index ]

PHP Cross Reference of PHK Manager

title

Body

[close]

/PHK/CLI/ -> Cmd.php (source)

   1  <?php
   2  //=============================================================================
   3  //
   4  // Copyright Francois Laupretre <phk@tekwire.net>
   5  //
   6  //   Licensed under the Apache License, Version 2.0 (the "License");
   7  //   you may not use this file except in compliance with the License.
   8  //   You may obtain a copy of the License at
   9  //
  10  //       http://www.apache.org/licenses/LICENSE-2.0
  11  //
  12  //   Unless required by applicable law or agreed to in writing, software
  13  //   distributed under the License is distributed on an "AS IS" BASIS,
  14  //   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15  //   See the License for the specific language governing permissions and
  16  //   limitations under the License.
  17  //
  18  //=============================================================================
  19  /**
  20  * @copyright Francois Laupretre <phk@tekwire.net>
  21  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0
  22  * @category PHK
  23  * @package PHK
  24  *///==========================================================================
  25  
  26  namespace PHK\CLI {
  27  
  28  if (!class_exists('PHK\CLI\Cmd',false))
  29  {
  30  
  31  //=============================================================================
  32  /**
  33  * phkmgr CLI script. Builds and manages PHK packages.
  34  *
  35  * API status: Private
  36  * Included in the PHK PHP runtime: No
  37  * Implemented in the extension: No
  38  *///==========================================================================
  39  
  40  class Cmd
  41  {
  42  //---------
  43  
  44  private static function errorAbort($msg,$usage=true)
  45  {
  46  if ($usage) $msg .= " - Use 'help' command for syntax";
  47  throw new \Exception($msg);
  48  }
  49  
  50  //---------
  51  
  52  private static function usage()
  53  {
  54  echo "
  55  Available commands :
  56  
  57    - build [-s <psf-path>] [-d <var>=<value> ...]] <package-path>
  58          Builds a PHK package
  59          Options :
  60              -s <psf-path> : the path to the Package Specification File. If this
  61                              option is not set, the PSF path is computed from
  62                              the package path (replacing file suffix with '.psf').
  63              -d <var>=<value> : Define a variable. In the PSF, variable expansion
  64                                 syntax is '\$(var)'. Can be set more than once.
  65  
  66    - check <package-path>
  67          Checks an existing package's integrity
  68          Options :
  69              -f <format> : Output format. Default is 'auto'.
  70  
  71      - help
  72          Display this message
  73  
  74  Global options :
  75  
  76    -v : Increase verbose level (can be set more than once)
  77    -q : Decrease verbose level (can be set more than once)
  78  
  79  More information at http://phk.tekwire.net\n\n";
  80  }
  81  
  82  //---------
  83  // Main
  84  // Options can be located before AND after the action keyword.
  85  
  86  public static function run($args)
  87  {
  88  $op=new Options;
  89  $op->parseAll($args);
  90  $action=(count($args)) ? array_shift($args) : 'help';
  91  
  92  switch($action)
  93      {
  94      case 'build':
  95          if (count($args)!=1) self::errorAbort("$action requires 1 argument");
  96          $phk_path=array_shift($args);
  97          \PHK\Build\PSF\Parser::build($phk_path,$op->option('psf_path'),$op->option('vars'));
  98          break;
  99  
 100      case 'check':
 101          if (count($args)!=1) self::errorAbort("$action requires 1 argument");
 102          $phk_path=array_shift($args);
 103          $mnt=\PHK\Mgr::mount($phk_path);
 104          $obj=\PHK\Mgr::instance($mnt);
 105          $errs=$obj->check();
 106          if (count($errs))
 107              {
 108              foreach($errs as $err) \Phool\Display::error($err);
 109              throw new \Exception("*** The check procedure found errors in $phk_path");
 110              }
 111          \Phool\Display::info('Check OK');
 112          break;
 113  
 114      case 'help':
 115          self::usage();
 116          break;
 117  
 118      default:
 119          self::errorAbort("Unknown action: '$action'");
 120      }
 121  }
 122  
 123  //---
 124  } // End of class
 125  //===========================================================================
 126  } // End of class_exists
 127  //===========================================================================
 128  } // End of namespace
 129  //===========================================================================
 130  ?>


Generated: Thu Jun 4 18:33:15 2015 Cross-referenced by PHPXref 0.7.1