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

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartcli',
version: '4.0.12',
version: '4.0.13',
description: 'A library that simplifies building reactive command-line applications using observables, with robust support for commands, arguments, options, aliases, and asynchronous operation management.'
}

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;

View File

@@ -1,7 +1,7 @@
// @pushrocks scope
import * as smartlog from '@push.rocks/smartlog';
import * as lik from '@push.rocks/lik';
import * as path from 'path';
import * as path from 'node:path';
import * as smartparam from '@push.rocks/smartobject';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartrx from '@push.rocks/smartrx';