fix(smartcli.helpers): Improve CLI argument parsing and Deno runtime detection; use getUserArgs consistently

This commit is contained in:
2025-10-28 14:59:46 +00:00
parent e905af4b21
commit 913f8556d0
5 changed files with 55 additions and 28 deletions

View File

@@ -15,12 +15,17 @@ export function getUserArgs(argv?: string[]): string[] {
// it's the most reliable for Deno run and compiled.
// deno-lint-ignore no-explicit-any
const g: any = typeof globalThis !== 'undefined' ? globalThis : {};
if (!useProvidedArgv && g.Deno && g.Deno.args && Array.isArray(g.Deno.args)) {
// 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) {
return g.Deno.args.slice();
}
const a =
argv ?? (typeof process !== 'undefined' && Array.isArray(process.argv) ? process.argv : []);
const a = argv ?? processArgv;
if (!Array.isArray(a) || a.length === 0) return [];