fix(smartcli): Allow passing argv to startParse and improve getUserArgs Deno/runtime handling; update tests and add license

This commit is contained in:
2025-10-28 15:42:39 +00:00
parent 5c65c43589
commit 01623eab2a
5 changed files with 17 additions and 11 deletions

View File

@@ -13,19 +13,15 @@ export function getUserArgs(argv?: string[]): string[] {
// Prefer Deno.args when available and no custom argv provided;
// it's the most reliable for Deno run and compiled.
// Deno.args is ALWAYS correct in Deno environments - it handles the internal bundle path automatically.
// deno-lint-ignore no-explicit-any
const g: any = typeof globalThis !== 'undefined' ? globalThis : {};
// Check if we should use Deno.args
// Skip Deno.args if process.argv has been manipulated (test scenario detection)
const processArgv = typeof process !== 'undefined' && Array.isArray(process.argv) ? process.argv : [];
const argvLooksManipulated = processArgv.length > 2 && g.Deno && g.Deno.args;
if (!useProvidedArgv && g.Deno && g.Deno.args && Array.isArray(g.Deno.args) && !argvLooksManipulated) {
if (!useProvidedArgv && g.Deno && g.Deno.args && Array.isArray(g.Deno.args)) {
return g.Deno.args.slice();
}
const a = argv ?? processArgv;
const a = argv ?? (typeof process !== 'undefined' && Array.isArray(process.argv) ? process.argv : []);
if (!Array.isArray(a) || a.length === 0) return [];