MCPcopy Create free account
hub / github.com/appium/appium / parseArgs

Method parseArgs

packages/appium/lib/cli/parser.ts:309–352  ·  view source on GitHub ↗

* Parses CLI args and returns Appium's normalized argument object. * * If no explicit subcommand is provided, this injects `server`. * `parse_args` is a backwards-compatible alias of this method.

(args: string[] = process.argv.slice(2))

Source from the content-addressed store, hash-verified

307 * `parse_args` is a backwards-compatible alias of this method.
308 */
309 parseArgs(args: string[] = process.argv.slice(2)): TransformedArgsMap {
310 if (!NON_SERVER_ARGS.has(args[0])) {
311 args.unshift(SERVER_SUBCOMMAND);
312 }
313
314 try {
315 const parsed = this.parser.parse_known_args(args);
316 const [knownArgs, unknownArgs] = parsed;
317 // XXX: you'd think that argparse, when given an alias for a subcommand,
318 // would set this value to the original subcommand name, but it doesn't.
319 if (knownArgs?.driverCommand === 'ls') {
320 knownArgs.driverCommand = 'list';
321 } else if (knownArgs?.pluginCommand === 'ls') {
322 knownArgs.pluginCommand = 'list';
323 }
324 if (unknownArgs?.length && (knownArgs.driverCommand === 'run' || knownArgs.pluginCommand === 'run')) {
325 return ArgParser._transformParsedArgs(knownArgs, unknownArgs);
326 } else if (unknownArgs?.length) {
327 if (knownArgs.allowUnknownArgs) {
328 // eslint-disable-next-line no-console
329 console.error(
330 `[WARN] Ignoring unrecognized arguments because '--allow-unknown-args' is set: ${unknownArgs.join(' ')}`,
331 );
332 return ArgParser._transformParsedArgs(knownArgs);
333 }
334 throw new Error(`[ERROR] Unrecognized arguments: ${unknownArgs.join(' ')}`);
335 }
336 return ArgParser._transformParsedArgs(knownArgs);
337 } catch (err) {
338 if (this.debug) {
339 throw err;
340 }
341 // this isn't tested via unit tests (we use `debug: true`) so may escape coverage.
342
343 /* istanbul ignore next */
344 {
345 // eslint-disable-next-line no-console
346 console.error(); // need an extra space since argparse prints usage.
347 // eslint-disable-next-line no-console
348 console.error(err instanceof Error ? err.message : String(err));
349 process.exit(1);
350 }
351 }
352 }
353}
354
355/**

Callers 3

parsePreConfigArgsMethod · 0.80
parser.spec.tsFile · 0.80
throwsUncoloredFunction · 0.80

Calls 2

_transformParsedArgsMethod · 0.80
errorMethod · 0.65

Tested by 1

throwsUncoloredFunction · 0.64