php-pharlite/bin/pharlite

83 lines
1.5 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
require_once __DIR__."/../vendor/autoload.php";
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);
$builder->build();