}
}
- call_user_func(array($this, $this->cmds[$command]['run']));
+ call_user_func(array($this, $this->cmds[$command]['run']), $this->args);
}
static function getSubFuncs(CLICommand $cmdclass, $prefix, array $subs)
return $arg;
}
+ static function cli_arg_typ_dir($arg)
+ {
+ $f = realpath($arg);
+ if ($f===false || !file_exists($f) || !is_dir($f))
+ {
+ echo "Requested path '$arg' does not exist.\n";
+ exit(1);
+ }
+ return $f;
+ }
+
static function cli_arg_typ_file($arg)
{
$f = realpath($arg);
$sp = str_repeat(' ', $l+2);
foreach($this->cmds as $name => $funcs)
{
- $inf = sprintf("%${l}s ", $name);
+ $inf = $name . substr($sp, strlen($name));
if (isset($funcs['inf']))
{
$inf .= call_user_func(array($this, $funcs['inf'])) . "\n";
echo "$f\n";
}
}
+
+ static function cli_cmd_inf_extract()
+ {
+ return "Extract a PHAR package to a directory.";
+ }
+
+ static function cli_cmd_arg_extract()
+ {
+ return array(
+ 'f' => array('type'=>'phar', 'val'=>NULL, 'required'=>1, 'inf'=>'<file> Specifies the PHAR file to extract.'),
+ '' => array('type'=>'dir', 'val'=>'.', 'inf'=>'<dir> Directory to extract to (defaults to \'.\''),
+ );
+ }
+
+ static function cli_cmd_run_extract($args)
+ {
+ $dir = $args['']['val'];
+ if (is_array($dir))
+ {
+ if (count($dir) != 1)
+ {
+ echo "Only one target directory allowed.\n";
+ exit(1);
+ }
+ else
+ {
+ $dir = $dir[0];
+ }
+ }
+ $phar = $args['f']['val'];
+ $base = $phar->getPathname();
+ $bend = strpos($base, '.phar');
+ $bend = strpos($base, '/', $bend);
+ $base = substr($base, 0, $bend + 1);
+ $blen = strlen($base);
+ foreach(new RecursiveIteratorIterator($phar) as $pn => $f)
+ {
+ $sub = substr($pn, $blen);
+ $target = $dir . '/' . $sub;
+ if (!file_exists(dirname($target)))
+ {
+ if (!@mkdir(dirname($target)))
+ {
+ echo " ..unable to create dir\n";
+ exit(1);
+ }
+ }
+ echo "$sub";
+ if (!@copy($f, $target))
+ {
+ echo " ...error\n";
+ }
+ else
+ {
+ echo " ...ok\n";
+ }
+ }
+ }
}
new PharCommand($argc, $argv);
}
}
- call_user_func(array($this, $this->cmds[$command]['run']));
+ call_user_func(array($this, $this->cmds[$command]['run']), $this->args);
}
static function getSubFuncs(CLICommand $cmdclass, $prefix, array $subs)
return $arg;
}
+ static function cli_arg_typ_dir($arg)
+ {
+ $f = realpath($arg);
+echo "DIR: '$arg' = '$f'\n";
+ if ($f===false || !file_exists($f) || !is_dir($f))
+ {
+ echo "Requested path '$arg' does not exist.\n";
+ exit(1);
+ }
+ return $f;
+ }
+
static function cli_arg_typ_file($arg)
{
$f = new SplFileInfo($arg);
$sp = str_repeat(' ', $l+2);
foreach($this->cmds as $name => $funcs)
{
- $inf = sprintf("%${l}s ", $name);
+ $inf = $name . substr($sp, strlen($name));
if (isset($funcs['inf']))
{
$inf .= call_user_func(array($this, $funcs['inf'])) . "\n";
echo "$f\n";
}
}
+
+ static function cli_cmd_inf_extract()
+ {
+ return "Extract a PHAR package to a directory.";
+ }
+
+ static function cli_cmd_arg_extract()
+ {
+ return array(
+ 'f' => array('type'=>'phar', 'val'=>NULL, 'required'=>1, 'inf'=>'<file> Specifies the PHAR file to extract.'),
+ '' => array('type'=>'dir', 'val'=>'.', 'inf'=>'<dir> Directory to extract to (defaults to \'.\''),
+ );
+ }
+
+ static function cli_cmd_run_extract($args)
+ {
+ $dir = $args['']['val'];
+ if (is_array($dir))
+ {
+ if (count($dir) != 1)
+ {
+ echo "Only one target directory allowed.\n";
+ exit(1);
+ }
+ else
+ {
+ $dir = $dir[0];
+ }
+ }
+ $phar = $args['f']['val'];
+ $base = $phar->getPathname();
+ $bend = strpos($base, '.phar');
+ $bend = strpos($base, '/', $bend);
+ $base = substr($base, 0, $bend + 1);
+ $blen = strlen($base);
+ foreach(new RecursiveIteratorIterator($phar) as $pn => $f)
+ {
+ $sub = substr($pn, $blen);
+ $target = $dir . '/' . $sub;
+ if (!file_exists(dirname($target)))
+ {
+ if (!@mkdir(dirname($target)))
+ {
+ echo " ..unable to create dir\n";
+ exit(1);
+ }
+ }
+ echo "$sub";
+ if (!@copy($f, $target))
+ {
+ echo " ...error\n";
+ }
+ else
+ {
+ echo " ...ok\n";
+ }
+ }
+ }
}
?>
\ No newline at end of file