From e3f5616320a173523c95c37787bbafff9d281add Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Mon, 12 Jan 2026 01:21:49 +0000 Subject: [PATCH] fix(core): Remove flawed safety check in getUserArgs and debug log - Fixed bug where CLI with no args would return entire argv including node path - Removed debug 'Wanted command: ...' log from startParse() --- package.json | 2 +- ts/smartcli.classes.smartcli.ts | 1 - ts/smartcli.helpers.ts | 7 +------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 80bbc42..ac1cf87 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@push.rocks/smartcli", "private": false, - "version": "4.0.19", + "version": "4.0.20", "description": "A library that simplifies building reactive command-line applications using observables, with robust support for commands, arguments, options, aliases, and asynchronous operation management.", "main": "dist_ts/index.js", "typings": "dist_ts/index.d.ts", diff --git a/ts/smartcli.classes.smartcli.ts b/ts/smartcli.classes.smartcli.ts index d57f2ab..e1793ff 100644 --- a/ts/smartcli.classes.smartcli.ts +++ b/ts/smartcli.classes.smartcli.ts @@ -136,7 +136,6 @@ export class Smartcli { console.log(this.version || 'unknown version'); return; } - console.log(`Wanted command: ${wantedCommand}`); for (const command of this.commandObservableMap.getArray()) { if (!wantedCommand) { const standardCommand = this.commandObservableMap.findSync((commandArg) => { diff --git a/ts/smartcli.helpers.ts b/ts/smartcli.helpers.ts index 73b3d26..fcca9d2 100644 --- a/ts/smartcli.helpers.ts +++ b/ts/smartcli.helpers.ts @@ -63,14 +63,9 @@ export function getUserArgs(argv?: string[]): string[] { offset = Math.min(2, a.length); } - // Safety: if offset would skip all elements and array is not empty, don't skip anything - // This handles edge cases like test environments with unusual argv setups - if (offset >= a.length && a.length > 0) { - offset = 0; - } - // Note: we intentionally avoid path/URL heuristics on argv[1] so we don't // accidentally drop the first user arg when it's a path-like value in compiled mode. + // When offset >= a.length, this correctly returns an empty array (no user args). return a.slice(offset); }