appium 2.0.0-beta.17 → 2.0.0-beta.20

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.
Files changed (53) hide show
  1. package/build/lib/appium-config.schema.json +0 -0
  2. package/build/lib/appium.js +84 -69
  3. package/build/lib/cli/argparse-actions.js +1 -1
  4. package/build/lib/cli/args.js +87 -223
  5. package/build/lib/cli/extension-command.js +2 -2
  6. package/build/lib/cli/extension.js +14 -6
  7. package/build/lib/cli/parser.js +142 -106
  8. package/build/lib/cli/utils.js +1 -1
  9. package/build/lib/config-file.js +141 -0
  10. package/build/lib/config.js +42 -64
  11. package/build/lib/driver-config.js +41 -20
  12. package/build/lib/drivers.js +1 -1
  13. package/build/lib/ext-config-io.js +165 -0
  14. package/build/lib/extension-config.js +110 -60
  15. package/build/lib/grid-register.js +19 -21
  16. package/build/lib/logsink.js +1 -1
  17. package/build/lib/main.js +135 -72
  18. package/build/lib/plugin-config.js +17 -8
  19. package/build/lib/schema/appium-config-schema.js +252 -0
  20. package/build/lib/schema/arg-spec.js +120 -0
  21. package/build/lib/schema/cli-args.js +173 -0
  22. package/build/lib/schema/cli-transformers.js +76 -0
  23. package/build/lib/schema/index.js +36 -0
  24. package/build/lib/schema/keywords.js +62 -0
  25. package/build/lib/schema/schema.js +357 -0
  26. package/build/lib/utils.js +26 -35
  27. package/lib/appium-config.schema.json +277 -0
  28. package/lib/appium.js +99 -75
  29. package/lib/cli/args.js +138 -335
  30. package/lib/cli/extension-command.js +7 -6
  31. package/lib/cli/extension.js +12 -4
  32. package/lib/cli/parser.js +248 -96
  33. package/lib/config-file.js +227 -0
  34. package/lib/config.js +71 -61
  35. package/lib/driver-config.js +66 -11
  36. package/lib/ext-config-io.js +287 -0
  37. package/lib/extension-config.js +209 -66
  38. package/lib/grid-register.js +24 -21
  39. package/lib/main.js +139 -68
  40. package/lib/plugin-config.js +32 -2
  41. package/lib/schema/appium-config-schema.js +286 -0
  42. package/lib/schema/arg-spec.js +218 -0
  43. package/lib/schema/cli-args.js +273 -0
  44. package/lib/schema/cli-transformers.js +123 -0
  45. package/lib/schema/index.js +2 -0
  46. package/lib/schema/keywords.js +119 -0
  47. package/lib/schema/schema.js +577 -0
  48. package/lib/utils.js +29 -52
  49. package/package.json +16 -11
  50. package/types/appium-config.d.ts +197 -0
  51. package/types/types.d.ts +201 -0
  52. package/build/lib/cli/parser-helpers.js +0 -106
  53. package/lib/cli/parser-helpers.js +0 -106
package/lib/cli/args.js CHANGED
@@ -1,321 +1,26 @@
1
+ // @ts-check
2
+
3
+ // @ts-ignore
1
4
  import { DEFAULT_BASE_PATH } from '@appium/base-driver';
2
- import {
3
- parseSecurityFeatures, parseJsonStringOrFile,
4
- parsePluginNames, parseInstallTypes, parseDriverNames
5
- } from './parser-helpers';
6
- import {
7
- INSTALL_TYPES, DEFAULT_APPIUM_HOME,
8
- DRIVER_TYPE, PLUGIN_TYPE
9
- } from '../extension-config';
10
- import {
11
- DEFAULT_CAPS_ARG
12
- } from './argparse-actions';
5
+ import _ from 'lodash';
6
+ import DriverConfig from '../driver-config';
7
+ import { APPIUM_HOME, DRIVER_TYPE, INSTALL_TYPES, PLUGIN_TYPE } from '../extension-config';
8
+ import PluginConfig from '../plugin-config';
9
+ import { toParserArgs } from '../schema/cli-args';
13
10
 
14
11
  const DRIVER_EXAMPLE = 'xcuitest';
15
12
  const PLUGIN_EXAMPLE = 'find_by_image';
16
13
  const USE_ALL_PLUGINS = 'all';
17
14
 
18
- // sharedArgs will be added to every subcommand
19
- const sharedArgs = [
20
- [['-ah', '--home', '--appium-home'], {
21
- required: false,
22
- default: process.env.APPIUM_HOME || DEFAULT_APPIUM_HOME,
23
- help: 'The path to the directory where Appium will keep installed drivers, plugins, and any other metadata necessary for its operation',
24
- dest: 'appiumHome',
25
- }],
26
-
27
- [['--log-filters'], {
28
- dest: 'logFilters',
29
- default: null,
30
- required: false,
31
- action: 'store_true',
32
- help: 'Set the full path to a JSON file containing one or more log filtering rules',
33
- }],
34
- ];
35
-
36
- const serverArgs = [
37
- [['--shell'], {
38
- required: false,
39
- default: null,
40
- help: 'Enter REPL mode',
41
- action: 'store_true',
42
- dest: 'shell',
43
- }],
44
-
45
- [['--drivers'], {
46
- required: false,
47
- default: [],
48
- help: `A comma-separated list of installed driver names that should be active for this ` +
49
- `server. All drivers will be active by default.`,
50
- type: parseDriverNames,
51
- dest: 'drivers',
52
- }],
53
-
54
- [['--plugins'], {
55
- required: false,
56
- default: [],
57
- help: `A comma-separated list of installed plugin names that should be active for this ` +
58
- `server. To activate all plugins, you can use the single string "${USE_ALL_PLUGINS}" ` +
59
- `as the value (e.g. --plugins=${USE_ALL_PLUGINS})`,
60
- type: parsePluginNames,
61
- dest: 'plugins',
62
- }],
63
-
64
- [['--allow-cors'], {
65
- required: false,
66
- default: false,
67
- action: 'store_true',
68
- help: 'Whether the Appium server should allow web browser connections from any host',
69
- dest: 'allowCors',
70
- }],
71
-
72
-
73
- [['-a', '--address'], {
74
- default: '0.0.0.0',
75
- required: false,
76
- help: 'IP Address to listen on',
77
- dest: 'address',
78
- }],
79
-
80
- [['-p', '--port'], {
81
- default: 4723,
82
- required: false,
83
- type: 'int',
84
- help: 'port to listen on',
85
- dest: 'port',
86
- }],
87
-
88
- [['-pa', '--base-path'], {
89
- required: false,
90
- default: DEFAULT_BASE_PATH,
91
- dest: 'basePath',
92
- help: 'Base path to use as the prefix for all webdriver routes running ' +
93
- `on this server`
94
- }],
95
-
96
- [['-ka', '--keep-alive-timeout'], {
97
- required: false,
98
- default: null,
99
- dest: 'keepAliveTimeout',
100
- type: 'int',
101
- help: 'Number of seconds the Appium server should apply as both the keep-alive timeout ' +
102
- 'and the connection timeout for all requests. Defaults to 600 (10 minutes).'
103
- }],
104
-
105
- [['-ca', '--callback-address'], {
106
- required: false,
107
- dest: 'callbackAddress',
108
- default: null,
109
- help: 'callback IP Address (default: same as --address)',
110
- }],
111
-
112
- [['-cp', '--callback-port'], {
113
- required: false,
114
- dest: 'callbackPort',
115
- default: null,
116
- type: 'int',
117
- help: 'callback port (default: same as port)',
118
- }],
119
-
120
- [['--session-override'], {
121
- default: false,
122
- dest: 'sessionOverride',
123
- action: 'store_true',
124
- required: false,
125
- help: 'Enables session override (clobbering)',
126
- }],
127
-
128
- [['-g', '--log'], {
129
- default: null,
130
- dest: 'logFile',
131
- required: false,
132
- help: 'Also send log output to this file',
133
- }],
134
-
135
- [['--log-level'], {
136
- choices: [
137
- 'info', 'info:debug', 'info:info', 'info:warn', 'info:error',
138
- 'warn', 'warn:debug', 'warn:info', 'warn:warn', 'warn:error',
139
- 'error', 'error:debug', 'error:info', 'error:warn', 'error:error',
140
- 'debug', 'debug:debug', 'debug:info', 'debug:warn', 'debug:error',
141
- ],
142
- default: 'debug',
143
- dest: 'loglevel',
144
- required: false,
145
- help: 'log level; default (console[:file]): debug[:debug]',
146
- }],
147
-
148
- [['--log-timestamp'], {
149
- default: false,
150
- required: false,
151
- help: 'Show timestamps in console output',
152
- action: 'store_true',
153
- dest: 'logTimestamp',
154
- }],
155
-
156
- [['--local-timezone'], {
157
- default: false,
158
- required: false,
159
- help: 'Use local timezone for timestamps',
160
- action: 'store_true',
161
- dest: 'localTimezone',
162
- }],
163
-
164
- [['--log-no-colors'], {
165
- default: false,
166
- required: false,
167
- help: 'Do not use colors in console output',
168
- action: 'store_true',
169
- dest: 'logNoColors',
170
- }],
171
-
172
- [['-G', '--webhook'], {
173
- default: null,
174
- required: false,
175
- dest: 'webhook',
176
- help: 'Also send log output to this HTTP listener, for example localhost:9876',
177
- }],
178
-
179
- [['--nodeconfig'], {
180
- required: false,
181
- default: null,
182
- dest: 'nodeconfig',
183
- help: 'Configuration JSON file to register appium with selenium grid',
184
- }],
185
-
186
- [['--show-config'], {
187
- default: false,
188
- dest: 'showConfig',
189
- action: 'store_true',
190
- required: false,
191
- help: 'Show info about the appium server configuration and exit',
192
- }],
193
-
194
- [['--no-perms-check'], {
195
- default: false,
196
- dest: 'noPermsCheck',
197
- action: 'store_true',
198
- required: false,
199
- help: 'Bypass Appium\'s checks to ensure we can read/write necessary files',
200
- }],
201
-
202
- [['--strict-caps'], {
203
- default: false,
204
- dest: 'enforceStrictCaps',
205
- action: 'store_true',
206
- required: false,
207
- help: 'Cause sessions to fail if desired caps are sent in that Appium ' +
208
- 'does not recognize as valid for the selected device',
209
- }],
210
-
211
- [['--tmp'], {
212
- default: null,
213
- dest: 'tmpDir',
214
- required: false,
215
- help: 'Absolute path to directory Appium can use to manage temporary ' +
216
- 'files, like built-in iOS apps it needs to move around. On *nix/Mac ' +
217
- 'defaults to /tmp, on Windows defaults to C:\\Windows\\Temp',
218
- }],
15
+ /** @type {Set<ExtensionType>} */
16
+ const EXTENSION_TYPES = new Set([DRIVER_TYPE, PLUGIN_TYPE]);
219
17
 
220
- [['--trace-dir'], {
221
- default: null,
222
- dest: 'traceDir',
223
- required: false,
224
- help: 'Absolute path to directory Appium use to save ios instruments ' +
225
- 'traces, defaults to <tmp dir>/appium-instruments',
226
- }],
227
-
228
- [['--debug-log-spacing'], {
229
- dest: 'debugLogSpacing',
230
- default: false,
231
- action: 'store_true',
232
- required: false,
233
- help: 'Add exaggerated spacing in logs to help with visual inspection',
234
- }],
235
-
236
-
237
- [['--long-stacktrace'], {
238
- dest: 'longStacktrace',
239
- default: false,
240
- required: false,
241
- action: 'store_true',
242
- help: 'Add long stack traces to log entries. Recommended for debugging only.',
243
- }],
244
-
245
-
246
- [['-dc', DEFAULT_CAPS_ARG], {
247
- dest: 'defaultCapabilities',
248
- default: {},
249
- type: parseJsonStringOrFile,
250
- required: false,
251
- help: 'Set the default desired capabilities, which will be set on each ' +
252
- 'session unless overridden by received capabilities. For example: ' +
253
- '[ \'{"app": "myapp.app", "deviceName": "iPhone Simulator"}\' ' +
254
- '| /path/to/caps.json ]'
255
- }],
256
-
257
- [['--relaxed-security'], {
258
- default: false,
259
- dest: 'relaxedSecurityEnabled',
260
- action: 'store_true',
261
- required: false,
262
- help: 'Disable additional security checks, so it is possible to use some advanced features, provided ' +
263
- 'by drivers supporting this option. Only enable it if all the ' +
264
- 'clients are in the trusted network and it\'s not the case if a client could potentially ' +
265
- 'break out of the session sandbox. Specific features can be overridden by ' +
266
- 'using the --deny-insecure flag',
267
- }],
268
-
269
- [['--allow-insecure'], {
270
- dest: 'allowInsecure',
271
- default: [],
272
- type: parseSecurityFeatures,
273
- required: false,
274
- help: 'Set which insecure features are allowed to run in this server\'s sessions. ' +
275
- 'Features are defined on a driver level; see documentation for more details. ' +
276
- 'This should be either a comma-separated list of feature names, or a path to ' +
277
- 'a file where each feature name is on a line. Note that features defined via ' +
278
- '--deny-insecure will be disabled, even if also listed here.',
279
- }],
280
-
281
- [['--deny-insecure'], {
282
- dest: 'denyInsecure',
283
- default: [],
284
- type: parseSecurityFeatures,
285
- required: false,
286
- help: 'Set which insecure features are not allowed to run in this server\'s sessions. ' +
287
- 'Features are defined on a driver level; see documentation for more details. ' +
288
- 'This should be either a comma-separated list of feature names, or a path to ' +
289
- 'a file where each feature name is on a line. Features listed here will not be ' +
290
- 'enabled even if also listed in --allow-insecure, and even if --relaxed-security ' +
291
- 'is turned on. For example: execute_driver_script,adb_shell',
292
- }],
293
-
294
- [['--driver-args'], {
295
- dest: 'driverArgs',
296
- default: {},
297
- type: parseJsonStringOrFile,
298
- required: false,
299
- help: 'Set the default desired client arguments for a driver, ' +
300
- 'For example: ' +
301
- '[ \'{"xcuitest": {"foo1": "bar1", "foo2": "bar2"}}\' ' +
302
- '| /path/to/driverArgs.json ]'
303
- }],
304
-
305
- [['--plugin-args'], {
306
- dest: 'pluginArgs',
307
- default: {},
308
- type: parseJsonStringOrFile,
309
- required: false,
310
- help: 'Set the default desired client arguments for a plugin, ' +
311
- 'For example: ' +
312
- '[ \'{"images": {"foo1": "bar1", "foo2": "bar2"}}\' ' +
313
- '| /path/to/pluginArgs.json ]'
314
- }],
315
- ];
18
+ const driverConfig = DriverConfig.getInstance(APPIUM_HOME);
19
+ const pluginConfig = PluginConfig.getInstance(APPIUM_HOME);
316
20
 
317
21
  // this set of args works for both drivers and plugins ('extensions')
318
- const globalExtensionArgs = [
22
+ /** @type {ArgumentDefinitions} */
23
+ const globalExtensionArgs = new Map([
319
24
  [['--json'], {
320
25
  required: false,
321
26
  default: false,
@@ -323,12 +28,32 @@ const globalExtensionArgs = [
323
28
  help: 'Use JSON for output format',
324
29
  dest: 'json'
325
30
  }]
326
- ];
327
-
328
- const extensionArgs = {[DRIVER_TYPE]: {}, [PLUGIN_TYPE]: {}};
329
-
31
+ ]);
32
+
33
+ /**
34
+ * Builds a Record of extension types to a Record of subcommands to their argument definitions
35
+ */
36
+ const getExtensionArgs = _.once(function getExtensionArgs () {
37
+ const extensionArgs = {};
38
+ for (const type of EXTENSION_TYPES) {
39
+ extensionArgs[type] = {
40
+ list: makeListArgs(type),
41
+ install: makeInstallArgs(type),
42
+ uninstall: makeUninstallArgs(type),
43
+ update: makeUpdateArgs(type),
44
+ run: makeRunArgs(type),
45
+ };
46
+ }
47
+ return /** @type {Record<ExtensionType, Record<string,ArgumentDefinitions[]>>} */ (extensionArgs);
48
+ });
49
+
50
+ /**
51
+ * Makes the opts for the `list` subcommand for each extension type.
52
+ * @param {ExtensionType} type
53
+ * @returns {ArgumentDefinitions}
54
+ */
330
55
  function makeListArgs (type) {
331
- return [
56
+ return new Map([
332
57
  ...globalExtensionArgs,
333
58
  [['--installed'], {
334
59
  required: false,
@@ -344,12 +69,16 @@ function makeListArgs (type) {
344
69
  help: 'Show information about newer versions',
345
70
  dest: 'showUpdates'
346
71
  }]
347
- ];
72
+ ]);
348
73
  }
349
74
 
350
-
75
+ /**
76
+ * Makes the opts for the `install` subcommand for each extension type
77
+ * @param {ExtensionType} type
78
+ * @returns {ArgumentDefinitions}
79
+ */
351
80
  function makeInstallArgs (type) {
352
- return [
81
+ return new Map([
353
82
  ...globalExtensionArgs,
354
83
  [[type], {
355
84
  type: 'str',
@@ -359,9 +88,9 @@ function makeInstallArgs (type) {
359
88
  [['--source'], {
360
89
  required: false,
361
90
  default: null,
362
- type: parseInstallTypes,
91
+ choices: INSTALL_TYPES,
363
92
  help: `Where to look for the ${type} if it is not one of Appium's verified ` +
364
- `${type}s. Possible values: ${JSON.stringify(INSTALL_TYPES)}`,
93
+ `${type}s. Possible values: ${INSTALL_TYPES.join(', ')}`,
365
94
  dest: 'installType'
366
95
  }],
367
96
  [['--package'], {
@@ -373,22 +102,33 @@ function makeInstallArgs (type) {
373
102
  `should be reported here, otherwise the install will probably fail.`,
374
103
  dest: 'packageName',
375
104
  }],
376
- ];
105
+ ]);
377
106
  }
378
107
 
108
+
109
+ /**
110
+ * Makes the opts for the `uninstall` subcommand for each extension type
111
+ * @param {ExtensionType} type
112
+ * @returns {ArgumentDefinitions}
113
+ */
379
114
  function makeUninstallArgs (type) {
380
- return [
115
+ return new Map([
381
116
  ...globalExtensionArgs,
382
117
  [[type], {
383
118
  type: 'str',
384
119
  help: 'Name of the driver to uninstall, for example: ' +
385
120
  type === DRIVER_TYPE ? DRIVER_EXAMPLE : PLUGIN_EXAMPLE
386
121
  }],
387
- ];
122
+ ]);
388
123
  }
389
124
 
125
+ /**
126
+ * Makes the opts for the `update` subcommand for each extension type
127
+ * @param {ExtensionType} type
128
+ * @returns {ArgumentDefinitions}
129
+ */
390
130
  function makeUpdateArgs (type) {
391
- return [
131
+ return new Map([
392
132
  ...globalExtensionArgs,
393
133
  [[type], {
394
134
  type: 'str',
@@ -403,11 +143,16 @@ function makeUpdateArgs (type) {
403
143
  help: `Include updates that might have a new major revision, and potentially include ` +
404
144
  `breaking changes`,
405
145
  }],
406
- ];
146
+ ]);
407
147
  }
408
148
 
149
+ /**
150
+ * Makes the opts for the `run` subcommand for each extension type
151
+ * @param {ExtensionType} type
152
+ * @returns {ArgumentDefinitions}
153
+ */
409
154
  function makeRunArgs (type) {
410
- return [
155
+ return new Map([
411
156
  ...globalExtensionArgs,
412
157
  [[type], {
413
158
  type: 'str',
@@ -420,20 +165,78 @@ function makeRunArgs (type) {
420
165
  help: `Name of the script to run from the ${type}. The script name must be cached ` +
421
166
  `inside the "scripts" field under "appium" inside the ${type}'s "package.json" file`
422
167
  }],
423
- ];
168
+ ]);
424
169
  }
425
170
 
426
- for (const type of [DRIVER_TYPE, PLUGIN_TYPE]) {
427
- extensionArgs[type].list = makeListArgs(type);
428
- extensionArgs[type].install = makeInstallArgs(type);
429
- extensionArgs[type].uninstall = makeUninstallArgs(type);
430
- extensionArgs[type].update = makeUpdateArgs(type);
431
- extensionArgs[type].run = makeRunArgs(type);
171
+ /**
172
+ * Derives the options for the `server` command from the schema, and adds the arguments
173
+ * which are disallowed in the config file.
174
+ * @returns {ArgumentDefinitions}
175
+ */
176
+ function getServerArgs () {
177
+ return new Map([
178
+ ...toParserArgs({
179
+ overrides: {
180
+ basePath: {
181
+ default: DEFAULT_BASE_PATH
182
+ },
183
+ }
184
+ }),
185
+ ...serverArgsDisallowedInConfig,
186
+ ]);
432
187
  }
433
188
 
189
+ /**
190
+ * These don't make sense in the context of a config file for obvious reasons.
191
+ * @type {ArgumentDefinitions}
192
+ */
193
+ const serverArgsDisallowedInConfig = new Map([
194
+ [
195
+ ['--shell'],
196
+ {
197
+ required: false,
198
+ default: null,
199
+ help: 'Enter REPL mode',
200
+ action: 'store_true',
201
+ dest: 'shell',
202
+ },
203
+ ],
204
+ [
205
+ ['--show-config'],
206
+ {
207
+ default: false,
208
+ dest: 'showConfig',
209
+ action: 'store_true',
210
+ required: false,
211
+ help: 'Show info about the appium server configuration and exit',
212
+ },
213
+ ],
214
+ [
215
+ ['--config'],
216
+ {
217
+ dest: 'configFile',
218
+ type: 'string',
219
+ required: false,
220
+ help: 'Explicit path to Appium configuration file',
221
+ },
222
+ ],
223
+ ]);
224
+
434
225
  export {
435
- sharedArgs,
436
- serverArgs,
437
- extensionArgs,
226
+ getServerArgs,
227
+ getExtensionArgs,
438
228
  USE_ALL_PLUGINS,
229
+ driverConfig,
230
+ pluginConfig,
231
+ APPIUM_HOME
439
232
  };
233
+
234
+ /**
235
+ * Alias
236
+ * @typedef {import('../ext-config-io').ExtensionType} ExtensionType
237
+ */
238
+
239
+ /**
240
+ * A tuple of argument aliases and argument options
241
+ * @typedef {Map<string[],import('argparse').ArgumentOptions>} ArgumentDefinitions
242
+ */
@@ -489,11 +489,6 @@ export default class ExtensionCommand {
489
489
  await this.config.updateExtension(ext, extData);
490
490
  }
491
491
 
492
- /**
493
- * @typedef RunOutput
494
- * @property {?string|undefined} error - error message if script ran unsuccessfuly, otherwise undefined
495
- * @property {string[]} output - script output
496
- */
497
492
  /**
498
493
  * Runs a script cached inside the "scripts" field under "appium"
499
494
  * inside of the driver/plugins "package.json" file. Will throw
@@ -543,7 +538,7 @@ export default class ExtensionCommand {
543
538
 
544
539
  try {
545
540
  await runner.join();
546
- log(this.isJsonOutput, `${scriptName} successfuly ran`.green);
541
+ log(this.isJsonOutput, `${scriptName} successfully ran`.green);
547
542
  return {output: output.getBuff()};
548
543
  } catch (err) {
549
544
  log(this.isJsonOutput, `Encountered an error when running '${scriptName}': ${err.message}`.red);
@@ -551,3 +546,9 @@ export default class ExtensionCommand {
551
546
  }
552
547
  }
553
548
  }
549
+
550
+ /**
551
+ * @typedef {Object} RunOutput
552
+ * @property {string|undefined} error - error message if script ran unsuccessfully, otherwise undefined
553
+ * @property {string[]} output - script output
554
+ */
@@ -6,6 +6,7 @@ import DriverConfig from '../driver-config';
6
6
  import PluginConfig from '../plugin-config';
7
7
  import { DRIVER_TYPE } from '../extension-config';
8
8
  import { errAndQuit, log, JSON_SPACES } from './utils';
9
+ import { APPIUM_HOME } from './args';
9
10
 
10
11
  /**
11
12
  * Run a subcommand of the 'appium driver' type. Each subcommand has its own set of arguments which
@@ -13,8 +14,10 @@ import { errAndQuit, log, JSON_SPACES } from './utils';
13
14
  *
14
15
  * @param {Object} args - JS object where the key is the parameter name (as defined in
15
16
  * driver-parser.js)
17
+ * @param {import('../ext-config-io').ExtensionType} type - Extension type
18
+ * @oaram {ExtensionConfig} [configObject] - Extension config object, if we have one
16
19
  */
17
- async function runExtensionCommand (args, type) {
20
+ async function runExtensionCommand (args, type, configObject) {
18
21
  // TODO driver config file should be locked while any of these commands are
19
22
  // running to prevent weird situations
20
23
  let jsonResult = null;
@@ -22,14 +25,19 @@ async function runExtensionCommand (args, type) {
22
25
  if (!extCmd) {
23
26
  throw new TypeError(`Cannot call ${type} command without a subcommand like 'install'`);
24
27
  }
25
- let {json, suppressOutput, appiumHome} = args;
28
+ let {json, suppressOutput} = args;
26
29
  if (suppressOutput) {
27
30
  json = true;
28
31
  }
29
32
  const logFn = (msg) => log(json, msg);
30
- const ConfigClass = type === DRIVER_TYPE ? DriverConfig : PluginConfig;
33
+ let config;
34
+ if (configObject) {
35
+ config = configObject;
36
+ config.log = logFn;
37
+ } else {
38
+ config = (type === DRIVER_TYPE ? DriverConfig : PluginConfig).getInstance(APPIUM_HOME, logFn);
39
+ }
31
40
  const CommandClass = type === DRIVER_TYPE ? DriverCommand : PluginCommand;
32
- const config = new ConfigClass(appiumHome, logFn);
33
41
  const cmd = new CommandClass({config, json});
34
42
  try {
35
43
  await config.read();