fix(smartcli): Improve CLI argument parsing, update deps and tests

This commit is contained in:
2025-10-28 06:27:29 +00:00
parent 44296dc57a
commit 6efd6232d1
8 changed files with 12248 additions and 3216 deletions

View File

@@ -123,11 +123,16 @@ export class Smartcli {
* start the process of evaluating commands
*/
public startParse(): void {
const parsedYArgs = plugins.yargsParser(process.argv);
const parsedYArgs = plugins.yargsParser([...process.argv]);
// lets handle commands
// Filter out runtime executable and script path from arguments
// Node.js: ["/path/to/node", "/path/to/script.js", ...args]
// Deno: ["deno", "/path/to/script.ts", ...args]
// Bun: ["/path/to/bun", "/path/to/script.ts", ...args]
let counter = 0;
let foundCommand = false;
const runtimeNames = ['node', 'deno', 'bun', 'tsx', 'ts-node'];
parsedYArgs._ = parsedYArgs._.filter((commandPartArg) => {
counter++;
if (typeof commandPartArg === 'number') {
@@ -135,7 +140,10 @@ export class Smartcli {
}
if (counter <= 2 && !foundCommand) {
const isPath = commandPartArg.startsWith('/');
foundCommand = !isPath;
const isRuntimeExecutable = runtimeNames.some(name =>
commandPartArg === name || commandPartArg.endsWith(`/${name}`)
);
foundCommand = !isPath && !isRuntimeExecutable;
return foundCommand;
} else {
return true;