Skip to content

Commit db492cd

Browse files
committed
add commands handling
1 parent 9c23610 commit db492cd

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

packages/cpu-prof/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@push-based/cpu-prof",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"type": "module",
55
"main": "./dist/index.cjs",
66
"module": "./dist/index.esm.js",

packages/cpu-prof/src/cli/commands/cpu-measure/handler.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,35 @@ export async function handler(argv: MeasureArgs): Promise<void> {
1818
['flag-main']: flagMain2,
1919
...commandOptions
2020
} = options;
21+
22+
// Determine the actual command to profile
23+
const cmdToRun = // Case 1: Explicit 'measure' command is used.
24+
// Example: `cpu-prof measure npm -v`
25+
// Here, `commandToProfile` will be `['npm', '-v']`.
26+
(
27+
commandToProfile && commandToProfile.length > 0
28+
? commandToProfile
29+
: // Case 2: Default command ('*') is used (i.e., 'measure' is not explicitly typed).
30+
// Example: `cpu-prof npm -v`
31+
// Here, `positionalArgs` (argv._) will be `['npm', '-v']`.
32+
positionalArgs
33+
) as string[];
34+
2135
const nodeOptions = {
2236
...(cpuProfDir ? { cpuProfDir } : {}),
2337
...(cpuProfInterval ? { cpuProfInterval } : {}),
2438
...(cpuProfName ? { cpuProfName } : {}),
2539
...(flagMain ? { flagMain } : {}),
2640
};
2741

28-
if (
29-
!commandToProfile ||
30-
!Array.isArray(commandToProfile) ||
31-
commandToProfile.length === 0
32-
) {
42+
if (!cmdToRun || !Array.isArray(cmdToRun) || cmdToRun.length === 0) {
3343
console.error(
34-
'❌ Error: No command or script provided to profile. Usage: cpu-measure <command_or_script.js> [args...]'
44+
'❌ Error: No command or script provided to profile. Usage: measure <command_or_script.js> [args...]'
3545
);
3646
process.exit(1);
3747
}
3848

39-
const [actualCommand, ...actualCommandArgs] = commandToProfile;
49+
const [actualCommand, ...actualCommandArgs] = cmdToRun;
4050

4151
// Filter commandOptions to prefer kebab-case and remove duplicate camelCase keys
4252
const filteredCommandOptions = filterCliOptions(commandOptions);

0 commit comments

Comments
 (0)