Task: #53687 Simplify cfg argument handling and keep --siteDir with JSON write input (-i)

This commit is contained in:
Alejandro Sosa 2026-03-26 12:27:12 +01:00
commit 2a391f4e0a
2 changed files with 24 additions and 57 deletions

32
bin/cfg
View file

@ -56,36 +56,6 @@ function readJsonInputFile(string $path): array
return $data;
}
// Pre-parse siteDir so it can be passed after positional args.
// The input helper library does not handle this case reliably.
$preparsedSiteDir = null;
$rawArgv = $_SERVER['argv'] ?? $GLOBALS['argv'] ?? null;
if (is_array($rawArgv) && !empty($rawArgv))
{
$filteredArgv = [$rawArgv[0]];
for ($idx = 1; $idx < count($rawArgv); $idx++)
{
$arg = $rawArgv[$idx];
if ($arg === '--siteDir')
{
$preparsedSiteDir = $rawArgv[$idx + 1] ?? '';
if (isset($rawArgv[$idx + 1])) $idx++;
continue;
}
if (str_starts_with($arg, '--siteDir='))
{
$preparsedSiteDir = substr($arg, strlen('--siteDir='));
continue;
}
$filteredArgv[] = $arg;
}
$_SERVER['argv'] = $filteredArgv;
$GLOBALS['argv'] = $filteredArgv;
}
$version = '0.4';
$actions = [ 'show', 'write', 'help' ];
@ -289,7 +259,7 @@ if ($pkgPath = $argv->find('pkgPath')) $cfg->pkgPath(rtrim($pkgPath, '/').'/');
$site = null;
$siteFlag = 0x01;
$siteInput = ($preparsedSiteDir !== null) ? $preparsedSiteDir : $argv->find('siteDir');
$siteInput = $argv->find('siteDir');
if ($siteInput !== null && $siteInput !== false)
{
$siteInput = trim((string)$siteInput);