Added command line option to init config file

This commit is contained in:
2020-06-28 23:56:01 +02:00
parent cd3e399e55
commit dd0e6c6b58
5 changed files with 180 additions and 29 deletions

View File

@ -14,12 +14,14 @@ 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");
define("FMT_AFTER", "\e[0m");
} else {
define("FMT_ERR", "");
define("FMT_WARN", "");
define("FMT_INFO", "");
define("FMT_AFTER", "");
define("FMT_NOTICE", "");
}
function print_error($fmt, ...$arg) {
@ -34,24 +36,33 @@ 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);
}
function show_app_usage() {
printf("usage\n");
printf("options:\n");
printf(" -I,--init Initialize a new configuration\n");
}
function parse_opts() {
$opts = getopt(
"ho:d:i",
"ho:d:iI",
[
"help",
"directory:",
"dir:",
"output:",
"install"
"install",
"init"
]
);
$parsed = [];
$parsed = [
'install' => false,
'init' => false
];
foreach ($opts as $option=>$value) {
switch ($option) {
@ -71,6 +82,10 @@ function parse_opts() {
case 'i':
case 'install':
$parsed['install'] = true;
break;
case 'I':
case 'init':
$parsed['init'] = true;
}
}
@ -78,11 +93,15 @@ function parse_opts() {
}
$opts = parse_opts();
if (false === parse_opts()) {
if (false === $opts) {
exit(1);
}
$path = getcwd();
$builder = new PharLite\Builder($path, $opts);
$builder->build();
if ($opts['init']) {
$builder->initConfig();
} else {
$builder->build();
}