Task: #53687 Support instance-specific cfg write targets and add coverage V2 #4
2 changed files with 24 additions and 57 deletions
Task: #53687 Simplify cfg argument handling and keep --siteDir with JSON write input (-i)
commit
2a391f4e0a
32
bin/cfg
32
bin/cfg
|
|
@ -56,36 +56,6 @@ function readJsonInputFile(string $path): array
|
||||||
return $data;
|
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';
|
$version = '0.4';
|
||||||
|
|
||||||
$actions = [ 'show', 'write', 'help' ];
|
$actions = [ 'show', 'write', 'help' ];
|
||||||
|
|
@ -289,7 +259,7 @@ if ($pkgPath = $argv->find('pkgPath')) $cfg->pkgPath(rtrim($pkgPath, '/').'/');
|
||||||
|
|
||||||
$site = null;
|
$site = null;
|
||||||
$siteFlag = 0x01;
|
$siteFlag = 0x01;
|
||||||
$siteInput = ($preparsedSiteDir !== null) ? $preparsedSiteDir : $argv->find('siteDir');
|
$siteInput = $argv->find('siteDir');
|
||||||
if ($siteInput !== null && $siteInput !== false)
|
if ($siteInput !== null && $siteInput !== false)
|
||||||
{
|
{
|
||||||
$siteInput = trim((string)$siteInput);
|
$siteInput = trim((string)$siteInput);
|
||||||
|
|
|
||||||
|
|
@ -156,8 +156,7 @@ class CfgTest extends TestCase
|
||||||
'write',
|
'write',
|
||||||
'Extension',
|
'Extension',
|
||||||
'module:code="X100"',
|
'module:code="X100"',
|
||||||
'--siteDir',
|
'--siteDir=owner_xyz',
|
||||||
'owner_xyz',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(0, $result['code'], $result['output']);
|
$this->assertSame(0, $result['code'], $result['output']);
|
||||||
|
|
@ -178,8 +177,7 @@ class CfgTest extends TestCase
|
||||||
'write',
|
'write',
|
||||||
'Extension',
|
'Extension',
|
||||||
'module:code="X100"',
|
'module:code="X100"',
|
||||||
'--siteDir',
|
'--siteDir=owner_xyz',
|
||||||
'owner_xyz',
|
|
||||||
]);
|
]);
|
||||||
$this->assertSame(0, $firstWrite['code'], $firstWrite['output']);
|
$this->assertSame(0, $firstWrite['code'], $firstWrite['output']);
|
||||||
|
|
||||||
|
|
@ -189,8 +187,7 @@ class CfgTest extends TestCase
|
||||||
'write',
|
'write',
|
||||||
'Extension',
|
'Extension',
|
||||||
'module:label="demo-module"',
|
'module:label="demo-module"',
|
||||||
'--siteDir',
|
'--siteDir=owner_xyz',
|
||||||
'owner_xyz',
|
|
||||||
]);
|
]);
|
||||||
$this->assertSame(0, $secondWrite['code'], $secondWrite['output']);
|
$this->assertSame(0, $secondWrite['code'], $secondWrite['output']);
|
||||||
|
|
||||||
|
|
@ -330,7 +327,7 @@ class CfgTest extends TestCase
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(1, $result['code']);
|
$this->assertSame(1, $result['code']);
|
||||||
$this->assertStringContainsString('Option --siteDir is empty.', $result['output']);
|
$this->assertStringContainsString('a value is required for --siteDir', $result['output']);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function runCfg(array $args): array
|
private function runCfg(array $args): array
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue