@midscene/shared 1.5.3 → 1.5.4-beta-20260310084708.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -79,10 +79,18 @@ function printCommandHelp(scriptName, cmd) {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function printVersion(scriptName, version) {
|
|
83
|
+
console.log(`${scriptName} v${version}`);
|
|
84
|
+
}
|
|
85
|
+
function printHelp(scriptName, commands, version) {
|
|
86
|
+
if (version) {
|
|
87
|
+
printVersion(scriptName, version);
|
|
88
|
+
console.log('');
|
|
89
|
+
}
|
|
83
90
|
console.log(`\nUsage: ${scriptName} <command> [options]\n`);
|
|
84
91
|
console.log('Commands:');
|
|
85
92
|
for (const { name, def } of commands)console.log(` ${name.padEnd(30)} ${def.description}`);
|
|
93
|
+
console.log(` ${'version'.padEnd(30)} Show CLI version`);
|
|
86
94
|
console.log(`\nRun "${scriptName} <command> --help" for more info.`);
|
|
87
95
|
}
|
|
88
96
|
async function runToolsCLI(tools, scriptName, options) {
|
|
@@ -97,17 +105,23 @@ async function runToolsCLI(tools, scriptName, options) {
|
|
|
97
105
|
name: removePrefix(def.name, options?.stripPrefix).toLowerCase(),
|
|
98
106
|
def
|
|
99
107
|
}));
|
|
108
|
+
const cliVersion = options?.version;
|
|
100
109
|
const [commandName, ...restArgs] = rawArgs;
|
|
101
110
|
if (!commandName || '--help' === commandName || '-h' === commandName) {
|
|
102
111
|
debug('showing help (no command or --help flag)');
|
|
103
|
-
printHelp(scriptName, commands);
|
|
112
|
+
printHelp(scriptName, commands, cliVersion);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if ('--version' === commandName || '-v' === commandName || 'version' === commandName.toLowerCase()) {
|
|
116
|
+
if (!cliVersion) throw new CLIError('Failed to determine CLI version');
|
|
117
|
+
printVersion(scriptName, cliVersion);
|
|
104
118
|
return;
|
|
105
119
|
}
|
|
106
120
|
const match = commands.find((c)=>c.name.toLowerCase() === commandName.toLowerCase());
|
|
107
121
|
if (!match) {
|
|
108
122
|
debug('unknown command: %s', commandName);
|
|
109
123
|
console.error(`Unknown command: ${commandName}`);
|
|
110
|
-
printHelp(scriptName, commands);
|
|
124
|
+
printHelp(scriptName, commands, cliVersion);
|
|
111
125
|
throw new CLIError(`Unknown command: ${commandName}`);
|
|
112
126
|
}
|
|
113
127
|
const parsedArgs = parseCliArgs(restArgs);
|
|
@@ -121,10 +121,18 @@ function printCommandHelp(scriptName, cmd) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
function
|
|
124
|
+
function printVersion(scriptName, version) {
|
|
125
|
+
console.log(`${scriptName} v${version}`);
|
|
126
|
+
}
|
|
127
|
+
function printHelp(scriptName, commands, version) {
|
|
128
|
+
if (version) {
|
|
129
|
+
printVersion(scriptName, version);
|
|
130
|
+
console.log('');
|
|
131
|
+
}
|
|
125
132
|
console.log(`\nUsage: ${scriptName} <command> [options]\n`);
|
|
126
133
|
console.log('Commands:');
|
|
127
134
|
for (const { name, def } of commands)console.log(` ${name.padEnd(30)} ${def.description}`);
|
|
135
|
+
console.log(` ${'version'.padEnd(30)} Show CLI version`);
|
|
128
136
|
console.log(`\nRun "${scriptName} <command> --help" for more info.`);
|
|
129
137
|
}
|
|
130
138
|
async function runToolsCLI(tools, scriptName, options) {
|
|
@@ -139,17 +147,23 @@ async function runToolsCLI(tools, scriptName, options) {
|
|
|
139
147
|
name: removePrefix(def.name, options?.stripPrefix).toLowerCase(),
|
|
140
148
|
def
|
|
141
149
|
}));
|
|
150
|
+
const cliVersion = options?.version;
|
|
142
151
|
const [commandName, ...restArgs] = rawArgs;
|
|
143
152
|
if (!commandName || '--help' === commandName || '-h' === commandName) {
|
|
144
153
|
debug('showing help (no command or --help flag)');
|
|
145
|
-
printHelp(scriptName, commands);
|
|
154
|
+
printHelp(scriptName, commands, cliVersion);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if ('--version' === commandName || '-v' === commandName || 'version' === commandName.toLowerCase()) {
|
|
158
|
+
if (!cliVersion) throw new CLIError('Failed to determine CLI version');
|
|
159
|
+
printVersion(scriptName, cliVersion);
|
|
146
160
|
return;
|
|
147
161
|
}
|
|
148
162
|
const match = commands.find((c)=>c.name.toLowerCase() === commandName.toLowerCase());
|
|
149
163
|
if (!match) {
|
|
150
164
|
debug('unknown command: %s', commandName);
|
|
151
165
|
console.error(`Unknown command: ${commandName}`);
|
|
152
|
-
printHelp(scriptName, commands);
|
|
166
|
+
printHelp(scriptName, commands, cliVersion);
|
|
153
167
|
throw new CLIError(`Unknown command: ${commandName}`);
|
|
154
168
|
}
|
|
155
169
|
const parsedArgs = parseCliArgs(restArgs);
|
package/package.json
CHANGED
package/src/cli/cli-runner.ts
CHANGED
|
@@ -20,6 +20,7 @@ interface CLICommand {
|
|
|
20
20
|
export interface CLIRunnerOptions {
|
|
21
21
|
stripPrefix?: string;
|
|
22
22
|
argv?: string[];
|
|
23
|
+
version?: string;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export class CLIError extends Error {
|
|
@@ -126,12 +127,25 @@ function printCommandHelp(scriptName: string, cmd: CLICommand): void {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
function
|
|
130
|
+
function printVersion(scriptName: string, version: string): void {
|
|
131
|
+
console.log(`${scriptName} v${version}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function printHelp(
|
|
135
|
+
scriptName: string,
|
|
136
|
+
commands: CLICommand[],
|
|
137
|
+
version?: string,
|
|
138
|
+
): void {
|
|
139
|
+
if (version) {
|
|
140
|
+
printVersion(scriptName, version);
|
|
141
|
+
console.log('');
|
|
142
|
+
}
|
|
130
143
|
console.log(`\nUsage: ${scriptName} <command> [options]\n`);
|
|
131
144
|
console.log('Commands:');
|
|
132
145
|
for (const { name, def } of commands) {
|
|
133
146
|
console.log(` ${name.padEnd(30)} ${def.description}`);
|
|
134
147
|
}
|
|
148
|
+
console.log(` ${'version'.padEnd(30)} Show CLI version`);
|
|
135
149
|
console.log(`\nRun "${scriptName} <command> --help" for more info.`);
|
|
136
150
|
}
|
|
137
151
|
|
|
@@ -155,12 +169,25 @@ export async function runToolsCLI(
|
|
|
155
169
|
name: removePrefix(def.name, options?.stripPrefix).toLowerCase(),
|
|
156
170
|
def,
|
|
157
171
|
}));
|
|
172
|
+
const cliVersion = options?.version;
|
|
158
173
|
|
|
159
174
|
const [commandName, ...restArgs] = rawArgs;
|
|
160
175
|
|
|
161
176
|
if (!commandName || commandName === '--help' || commandName === '-h') {
|
|
162
177
|
debug('showing help (no command or --help flag)');
|
|
163
|
-
printHelp(scriptName, commands);
|
|
178
|
+
printHelp(scriptName, commands, cliVersion);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (
|
|
183
|
+
commandName === '--version' ||
|
|
184
|
+
commandName === '-v' ||
|
|
185
|
+
commandName.toLowerCase() === 'version'
|
|
186
|
+
) {
|
|
187
|
+
if (!cliVersion) {
|
|
188
|
+
throw new CLIError('Failed to determine CLI version');
|
|
189
|
+
}
|
|
190
|
+
printVersion(scriptName, cliVersion);
|
|
164
191
|
return;
|
|
165
192
|
}
|
|
166
193
|
|
|
@@ -170,7 +197,7 @@ export async function runToolsCLI(
|
|
|
170
197
|
if (!match) {
|
|
171
198
|
debug('unknown command: %s', commandName);
|
|
172
199
|
console.error(`Unknown command: ${commandName}`);
|
|
173
|
-
printHelp(scriptName, commands);
|
|
200
|
+
printHelp(scriptName, commands, cliVersion);
|
|
174
201
|
throw new CLIError(`Unknown command: ${commandName}`);
|
|
175
202
|
}
|
|
176
203
|
|