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()
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartcli",
|
"name": "@push.rocks/smartcli",
|
||||||
"private": false,
|
"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.",
|
"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",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
|||||||
@@ -136,7 +136,6 @@ export class Smartcli {
|
|||||||
console.log(this.version || 'unknown version');
|
console.log(this.version || 'unknown version');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(`Wanted command: ${wantedCommand}`);
|
|
||||||
for (const command of this.commandObservableMap.getArray()) {
|
for (const command of this.commandObservableMap.getArray()) {
|
||||||
if (!wantedCommand) {
|
if (!wantedCommand) {
|
||||||
const standardCommand = this.commandObservableMap.findSync((commandArg) => {
|
const standardCommand = this.commandObservableMap.findSync((commandArg) => {
|
||||||
|
|||||||
@@ -63,14 +63,9 @@ export function getUserArgs(argv?: string[]): string[] {
|
|||||||
offset = Math.min(2, a.length);
|
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
|
// 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.
|
// 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);
|
return a.slice(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user