98 lines
3.1 KiB
PHP
98 lines
3.1 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
use wapmorgan\UnifiedArchive\CamApplication;
|
|
use wapmorgan\UnifiedArchive\UnifiedArchive;
|
|
|
|
$paths = [
|
|
// as a root package or phar
|
|
__DIR__.'/../vendor/autoload.php',
|
|
// as a dependency from bin
|
|
__DIR__.'/../autoload.php',
|
|
// as a dependency from package folder
|
|
__DIR__.'/../../../autoload.php',
|
|
];
|
|
function init_composer(array $paths) {
|
|
foreach ($paths as $path) {
|
|
if (file_exists($path)) {
|
|
require_once $path;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
if (!init_composer($paths)) die('Run `composer install` firstly.'.PHP_EOL);
|
|
if (!class_exists('\Docopt')) die('Install docopt firsly. Run `composer require docopt/docopt ~1.0`.'.PHP_EOL);
|
|
|
|
$version = UnifiedArchive::VERSION;
|
|
$doc = <<<DOC
|
|
Universal console archive manager for Windows/Linux (part of UnifiedArchive $version).
|
|
|
|
USAGE: cam (-l|--list) ARCHIVE
|
|
cam (-t|--table) ARCHIVE
|
|
cam (-i|--info) ARCHIVE
|
|
cam (-e|--extract) [--output=DIR] [--replace=(all|ask|none|time|size)] [--flat=(file|path)] [--exclude=PATTERN] ARCHIVE [FILES_IN_ARCHIVE...]
|
|
cam (-p|--print) ARCHIVE FILES_IN_ARCHIVE...
|
|
cam (-d|--details) ARCHIVE FILES_IN_ARCHIVE...
|
|
cam (-x|--delete) ARCHIVE FILES_IN_ARCHIVE...
|
|
cam (-a|--add) ARCHIVE FILES_ON_DISK...
|
|
cam (-c|--create) ARCHIVE FILES_ON_DISK...
|
|
cam (-f|--formats)
|
|
|
|
ACTIONS:
|
|
-l(--list) List files in archive
|
|
-t(--table) List files as table in archive
|
|
-i(--info) Summary about archive
|
|
|
|
-e(--extract) Extract from archive
|
|
|
|
-p(--print) Extract archive file content on terminal
|
|
-d(--details) Details about file in archive
|
|
-x(--delete) Delete files from archive
|
|
|
|
-a(--add) Pack files to archive
|
|
-c(--create) Create new archive
|
|
|
|
OPTIONS:
|
|
for --extract (-e):
|
|
--replace=all|ask|none|time|size
|
|
Set how should be resolved cases in that extracting files already exist.
|
|
all - replaces all files
|
|
ask - ask for manual resolution on every case
|
|
none - preserve all existing on disk files
|
|
time - selects file with later timestamp
|
|
size - selects file with bigger size
|
|
|
|
--flat=[file,path]
|
|
Removes all hierarchy and stores all files in one directory. With path option file name will be prepended with in-archive path (all "/" replaced by "-").
|
|
|
|
--exclude FILES... or
|
|
--exclude /PATTERN/
|
|
Excludes one or few files, directories by exact in-archive path or by regular expression pattern.
|
|
|
|
--output=DIRECTORY
|
|
Set output directory in that all files will be extracted.
|
|
DOC;
|
|
|
|
$args = Docopt::handle($doc, ['version' => UnifiedArchive::VERSION]);
|
|
|
|
$actions = array(
|
|
'l:list' => 'listArray',
|
|
't:table' => 'table',
|
|
'i:info' => 'info',
|
|
'e:extract' => 'extract',
|
|
'p:print' => 'printFile',
|
|
'd:details' => 'details',
|
|
'x:delete' => 'delete',
|
|
'a:add' => 'add',
|
|
'c:create' => 'create',
|
|
'f:formats' => 'checkFormats',
|
|
);
|
|
|
|
foreach ($actions as $arg => $v) {
|
|
$arg = explode(':', $arg);
|
|
if ($args['-'.$arg[0]] === true || $args['--'.$arg[1]] === true) {
|
|
$application = new CamApplication();
|
|
call_user_func(array($application, $v), $args);
|
|
}
|
|
}
|