php-pharlite/bin/pharlite

108 lines
2.1 KiB
Plaintext
Raw Permalink Normal View History

2018-04-05 23:22:42 +00:00
#!/usr/bin/env php
<?php
2018-04-05 23:35:44 +00:00
if (is_dir(__DIR__."/../vendor"))
2018-04-05 23:31:22 +00:00
require_once __DIR__."/../vendor/autoload.php";
2018-04-05 23:35:44 +00:00
elseif (file_exists(__DIR__."/../../../autoload.php"))
require_once __DIR__."/../../../autoload.php";
2018-04-05 23:31:22 +00:00
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_NOTICE", "\e[33m");
2018-04-05 23:22:42 +00:00
define("FMT_AFTER", "\e[0m");
} else {
define("FMT_ERR", "");
define("FMT_WARN", "");
define("FMT_INFO", "");
define("FMT_AFTER", "");
define("FMT_NOTICE", "");
2018-04-05 23:22:42 +00:00
}
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 print_notice($fmt, ...$arg) {
fprintf(STDOUT, FMT_NOTICE.$fmt.FMT_AFTER.PHP_EOL, ...$arg);
}
2018-04-05 23:22:42 +00:00
function show_app_usage() {
printf("options:\n");
printf(" -I,--init Initialize a new configuration\n");
2018-04-05 23:22:42 +00:00
}
function parse_opts() {
$opts = getopt(
"ho:d:iI",
2018-04-05 23:22:42 +00:00
[
"help",
"directory:",
"dir:",
"output:",
"install",
"init"
2018-04-05 23:22:42 +00:00
]
);
$parsed = [
'install' => false,
'init' => false
];
2018-04-05 23:22:42 +00:00
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;
break;
case 'I':
case 'init':
$parsed['init'] = true;
2018-04-05 23:22:42 +00:00
}
}
return $parsed;
}
$opts = parse_opts();
if (false === $opts) {
2018-04-05 23:22:42 +00:00
exit(1);
}
$path = getcwd();
$builder = new PharLite\Builder($path, $opts);
if ($opts['init']) {
$builder->initConfig();
} else {
$builder->build();
}