php-pharlite/bin/pharlite

89 lines
1.7 KiB
Plaintext
Raw Normal View History

2018-04-05 23:22:42 +00:00
#!/usr/bin/env php
<?php
2018-04-05 23:31:22 +00:00
if (file_exists(__DIR__."/../vendor"))
require_once __DIR__."/../vendor/autoload.php";
elseif (file_exists(__DIR__."/../../../vendor"))
require_once __DIR__."/../../../vendor/autoload.php";
else
die("Could not locate composer vendor/autoload.php");
2018-04-05 23:22:42 +00:00
define("PHARLITE_VERSION", "0.1.x");
if (posix_isatty(STDOUT)) {
define("FMT_ERR", "\e[31;1m");
define("FMT_WARN", "\e[33;1m");
define("FMT_INFO", "\e[32m");
define("FMT_AFTER", "\e[0m");
} else {
define("FMT_ERR", "");
define("FMT_WARN", "");
define("FMT_INFO", "");
define("FMT_AFTER", "");
}
function print_error($fmt, ...$arg) {
fprintf(STDOUT, FMT_ERR.$fmt."ERROR: ".FMT_AFTER.PHP_EOL, ...$arg);
}
function print_warn($fmt, ...$arg) {
fprintf(STDOUT, FMT_WARN.$fmt.FMT_AFTER.PHP_EOL, ...$arg);
}
function print_info($fmt, ...$arg) {
fprintf(STDOUT, FMT_INFO.$fmt.FMT_AFTER.PHP_EOL, ...$arg);
}
function show_app_usage() {
printf("usage\n");
}
function parse_opts() {
$opts = getopt(
"ho:d:i",
[
"help",
"directory:",
"dir:",
"output:",
"install"
]
);
$parsed = [];
foreach ($opts as $option=>$value) {
switch ($option) {
case 'h':
case 'help':
show_app_usage();
return false;
case 'd':
case 'dir':
case 'directory':
$parsed['dir'] = $value;
break;
case 'o':
case 'output':
$parsed['output'] = $value;
break;
case 'i':
case 'install':
$parsed['install'] = true;
}
}
return $parsed;
}
$opts = parse_opts();
if (false === parse_opts()) {
exit(1);
}
$path = getcwd();
$builder = new PharLite\Builder($path, $opts);
2018-04-05 23:31:22 +00:00
$builder->build();