fix(smartcli): Improve CLI argument parsing, update deps and tests
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user