public function run($argc, array $argv)
{
try {
/* load the phar(s) */
$list = $this->load();
/* installer hooks */
$hook = $this->hooks($list);
} catch (\Exception $e) {
$this->error("%s\n", $e->getMessage());
exit(self::EEXTRACT);
}
/* standard arg stuff */
$errs = [];
$prog = array_shift($argv);
foreach ($this->args->parse(--$argc, $argv) as $error) {
$errs[] = $error;
}
if ($this->args["help"]) {
$this->header();
$this->help($prog);
exit;
}
try {
foreach (["signature", "name", "date", "license", "release", "version"] as $opt) {
if ($this->args[$opt]) {
printf("%s\n", $this->metadata($opt));
exit;
}
}
} catch (\Exception $e) {
$this->error("%s\n", $e->getMessage());
exit(self::EARGS);
}
foreach ($this->args->validate() as $error) {
$errs[] = $error;
}
if ($errs) {
if (!$this->args["quiet"]) {
$this->header();
}
foreach ($errs as $err) {
$this->error("%s\n", $err);
}
if (!$this->args["quiet"]) {
$this->help($prog);
}
exit(self::EARGS);
}
try {
/* post process hooks */
foreach ($hook as $sdir) {
$sdir->setArgs($this->args);
}
} catch (\Exception $e) {
$this->error("%s\n", $e->getMessage());
exit(self::EARGS);
}
/* install packages */
try {
foreach ($list as $phar) {
$this->info("Installing %s ...\n", basename($phar->getPath()));
$this->install($list[$phar]);
$this->activate($list[$phar]);
$this->info("Successfully installed %s!\n", basename($phar->getPath()));
}
} catch (\Exception $e) {
$this->error("%s\n", $e->getMessage());
exit(self::EINSTALL);
}
}