]> granicus.if.org Git - php/commitdiff
- Implement auto/optional for pack -p
authorMarcus Boerger <helly@php.net>
Mon, 28 May 2007 15:20:31 +0000 (15:20 +0000)
committerMarcus Boerger <helly@php.net>
Mon, 28 May 2007 15:20:31 +0000 (15:20 +0000)
ext/phar/Makefile.frag
ext/phar/phar.php
ext/phar/phar/pharcommand.inc

index 682c8ca07e79aa2543c6f83f568262479a794569..734f0e6d58122bdd8f0f33ef7367c226604b03c1 100755 (executable)
@@ -5,6 +5,6 @@ $(srcdir)/phar_path_check.c: $(srcdir)/phar_path_check.re
 pharcmd: $(builddir)/phar.phar
 
 $(builddir)/phar.phar: $(srcdir)/phar/*.inc $(srcdir)/phar/*.php
-       php -d phar.readonly=0 $(srcdir)/phar.php pack -f $(builddir)/phar.phar -a pharcommand -c auto -x CVS -s $(srcdir)/phar/phar.php -h sha1 $(srcdir)/phar/
+       php -d phar.readonly=0 $(srcdir)/phar.php pack -f $(builddir)/phar.phar -a pharcommand -c auto -x CVS -p optional -s $(srcdir)/phar/phar.php -h sha1 $(srcdir)/phar/
        @chmod +x $(builddir)/phar.phar
 
index 067ecc002d46f6dc6eece6a2672da7a9ee75d6a9..487e591855452e1a92f7848b1b6dee222da5a0dc 100644 (file)
@@ -369,6 +369,29 @@ class PharCommand extends CLICommand
                return substr($haystack, -strlen($needle)) == $needle;
        }
 
+       static function cli_arg_typ_loader($arg)
+       {
+               if ($arg == 'auto')
+               {
+                       $found = NULL;
+                       foreach(split("\n", `pear list-files PHP_Archive`) as $ent)
+                       {
+                               $matches = NULL;
+                               if (preg_match(",^php[ \t]+([^ \t].*pear[\\\\/]PHP[\\\\/]Archive.php)$,", $ent, $matches))
+                               {
+                                       $found = $matches[1];
+                                       break;
+                               }
+                       }
+                       if (!isset($found) && $arg != 'optional') {
+                               echo "Pear package PHP_Archive or Archive.php class file not found.\n";
+                               exit(1);
+                       }
+                       $arg = $found;
+               }
+               return self::cli_arg_typ_file($arg);
+       }
+
        static function cli_arg_typ_pharnew($arg)
        {
                $pharfile = self::cli_arg_typ_filenew($arg);
@@ -459,7 +482,7 @@ class PharCommand extends CLICommand
                        'f' => array('typ'=>'pharnew', 'val'=>NULL,      'required'=>1, 'inf'=>'<file>   Specifies the phar file to work on.'),
                        'h' => array('typ'=>'select',  'val'=>NULL,                     'inf'=>'<method> Selects the hash algorithmn.', 'select'=>array('md5'=>'MD5','sha1'=>'SHA1','sha256'=>'SHA256','sha512'=>'SHA512')),
                        'i' => array('typ'=>'regex',   'val'=>NULL,                     'inf'=>'<regex>  Specifies a regular expression for input files.'),
-                       'p' => array('typ'=>'file',    'val'=>NULL,                     'inf'=>'<loader> Location of PHP_Archive class file (pear list-files PHP_Archive).'),
+                       'p' => array('typ'=>'loader',  'val'=>NULL,                     'inf'=>'<loader> Location of PHP_Archive class file (pear list-files PHP_Archive). You can use \'auto\' or \'optional\' to locate it automatically using the mentioned pear command. When using \'optional\' the command does not error out when the class file cannot be located.'),
                        's' => array('typ'=>'file',    'val'=>NULL,                     'inf'=>'<stub>   Select the stub file (excluded from list of input files/dirs).'),
                        'x' => array('typ'=>'regex',   'val'=>NULL,                     'inf'=>'<regex>  Regular expression for input files to exclude.'),
                        ''  => array('typ'=>'any',     'val'=>NULL,      'required'=>1, 'inf'=>'         Any number of input files and directories.'),
index 2df4189f801ba20b155a89b20e456ec73f4ce667..5d19abdec2c70ca9395244f8470625d9feaddca8 100755 (executable)
@@ -109,9 +109,9 @@ class PharCommand extends CLICommand
                 'inf' => '<meta>   Meta data to store with entry (serialized php data).'
             ),
             'p' => array(
-                'typ' => 'file',
+                'typ' => 'loader',
                 'val'  => NULL,
-                'inf'  => '<loader> Location of PHP_Archive class file (pear list-files PHP_Archive).',
+                'inf'  => '<loader> Location of PHP_Archive class file (pear list-files PHP_Archive). You can use \'auto\' or \'optional\' to locate it automatically using the mentioned pear command. When using \'optional\' the command does not error out when the class file cannot be located.',
             ),
             's' => array(
                 'typ' => 'file',
@@ -176,6 +176,35 @@ class PharCommand extends CLICommand
         return substr($haystack, -strlen($needle)) == $needle;
     }
     // }}}
+    // {{{ static function cli_arg_typ_loader
+    /**
+     * Argument type loader
+     *
+     * @param string $arg   Either 'auto' or an filename that contains class 
+     *                      PHP_Archive
+     * @param  string $cfg  Configuration to pass to a new file
+     * @param  string $key  The key 
+     * @return string $arg  The argument.
+     */
+    static function cli_arg_typ_loader($arg, $cfg, $key)
+    {
+        if ($arg == 'auto' || $arg == 'optional') {
+            $found = NULL;
+            foreach(split("\n", `pear list-files PHP_Archive`) as $ent) {
+                $matches = NULL;
+                if (preg_match(",^php[ \t]+([^ \t].*pear[\\\\/]PHP[\\\\/]Archive.php)$,", $ent, $matches)) {
+                    $found = $matches[1];
+                    break;
+                }
+            }
+            if (!isset($found) && $arg != 'optional') {
+                self::error("Pear package PHP_Archive or Archive.php class file not found.\n");
+            }
+            $arg = $found;
+        }
+        return self::cli_arg_typ_file($arg);
+    }
+    // }}}
     // {{{ static function cli_arg_typ_pharnew
     /**
      * Argument type new phar