appium 2.0.0-beta.9 → 2.0.0-rc.2

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 (208) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +149 -58
  3. package/build/lib/appium.d.ts +229 -0
  4. package/build/lib/appium.d.ts.map +1 -0
  5. package/build/lib/appium.js +677 -449
  6. package/build/lib/appium.js.map +1 -0
  7. package/build/lib/cli/args.d.ts +17 -0
  8. package/build/lib/cli/args.d.ts.map +1 -0
  9. package/build/lib/cli/args.js +263 -300
  10. package/build/lib/cli/args.js.map +1 -0
  11. package/build/lib/cli/driver-command.d.ts +102 -0
  12. package/build/lib/cli/driver-command.d.ts.map +1 -0
  13. package/build/lib/cli/driver-command.js +131 -81
  14. package/build/lib/cli/driver-command.js.map +1 -0
  15. package/build/lib/cli/extension-command.d.ts +402 -0
  16. package/build/lib/cli/extension-command.d.ts.map +1 -0
  17. package/build/lib/cli/extension-command.js +799 -383
  18. package/build/lib/cli/extension-command.js.map +1 -0
  19. package/build/lib/cli/extension.d.ts +23 -0
  20. package/build/lib/cli/extension.d.ts.map +1 -0
  21. package/build/lib/cli/extension.js +70 -68
  22. package/build/lib/cli/extension.js.map +1 -0
  23. package/build/lib/cli/parser.d.ts +84 -0
  24. package/build/lib/cli/parser.d.ts.map +1 -0
  25. package/build/lib/cli/parser.js +252 -148
  26. package/build/lib/cli/parser.js.map +1 -0
  27. package/build/lib/cli/plugin-command.d.ts +99 -0
  28. package/build/lib/cli/plugin-command.d.ts.map +1 -0
  29. package/build/lib/cli/plugin-command.js +125 -81
  30. package/build/lib/cli/plugin-command.js.map +1 -0
  31. package/build/lib/cli/utils.d.ts +29 -0
  32. package/build/lib/cli/utils.d.ts.map +1 -0
  33. package/build/lib/cli/utils.js +72 -51
  34. package/build/lib/cli/utils.js.map +1 -0
  35. package/build/lib/config-file.d.ts +100 -0
  36. package/build/lib/config-file.d.ts.map +1 -0
  37. package/build/lib/config-file.js +207 -0
  38. package/build/lib/config-file.js.map +1 -0
  39. package/build/lib/config.d.ts +49 -0
  40. package/build/lib/config.d.ts.map +1 -0
  41. package/build/lib/config.js +262 -223
  42. package/build/lib/config.js.map +1 -0
  43. package/build/lib/constants.d.ts +56 -0
  44. package/build/lib/constants.d.ts.map +1 -0
  45. package/build/lib/constants.js +73 -0
  46. package/build/lib/constants.js.map +1 -0
  47. package/build/lib/extension/driver-config.d.ts +82 -0
  48. package/build/lib/extension/driver-config.d.ts.map +1 -0
  49. package/build/lib/extension/driver-config.js +210 -0
  50. package/build/lib/extension/driver-config.js.map +1 -0
  51. package/build/lib/extension/extension-config.d.ts +270 -0
  52. package/build/lib/extension/extension-config.d.ts.map +1 -0
  53. package/build/lib/extension/extension-config.js +601 -0
  54. package/build/lib/extension/extension-config.js.map +1 -0
  55. package/build/lib/extension/index.d.ts +48 -0
  56. package/build/lib/extension/index.d.ts.map +1 -0
  57. package/build/lib/extension/index.js +105 -0
  58. package/build/lib/extension/index.js.map +1 -0
  59. package/build/lib/extension/manifest-migrations.d.ts +27 -0
  60. package/build/lib/extension/manifest-migrations.d.ts.map +1 -0
  61. package/build/lib/extension/manifest-migrations.js +134 -0
  62. package/build/lib/extension/manifest-migrations.js.map +1 -0
  63. package/build/lib/extension/manifest.d.ts +145 -0
  64. package/build/lib/extension/manifest.d.ts.map +1 -0
  65. package/build/lib/extension/manifest.js +528 -0
  66. package/build/lib/extension/manifest.js.map +1 -0
  67. package/build/lib/extension/package-changed.d.ts +11 -0
  68. package/build/lib/extension/package-changed.d.ts.map +1 -0
  69. package/build/lib/extension/package-changed.js +62 -0
  70. package/build/lib/extension/package-changed.js.map +1 -0
  71. package/build/lib/extension/plugin-config.d.ts +56 -0
  72. package/build/lib/extension/plugin-config.d.ts.map +1 -0
  73. package/build/lib/extension/plugin-config.js +102 -0
  74. package/build/lib/extension/plugin-config.js.map +1 -0
  75. package/build/lib/grid-register.d.ts +10 -0
  76. package/build/lib/grid-register.d.ts.map +1 -0
  77. package/build/lib/grid-register.js +122 -144
  78. package/build/lib/grid-register.js.map +1 -0
  79. package/build/lib/logger.d.ts +3 -0
  80. package/build/lib/logger.d.ts.map +1 -0
  81. package/build/lib/logger.js +5 -17
  82. package/build/lib/logger.js.map +1 -0
  83. package/build/lib/logsink.d.ts +4 -0
  84. package/build/lib/logsink.d.ts.map +1 -0
  85. package/build/lib/logsink.js +189 -184
  86. package/build/lib/logsink.js.map +1 -0
  87. package/build/lib/main.d.ts +62 -0
  88. package/build/lib/main.d.ts.map +1 -0
  89. package/build/lib/main.js +406 -234
  90. package/build/lib/main.js.map +1 -0
  91. package/build/lib/schema/arg-spec.d.ts +143 -0
  92. package/build/lib/schema/arg-spec.d.ts.map +1 -0
  93. package/build/lib/schema/arg-spec.js +164 -0
  94. package/build/lib/schema/arg-spec.js.map +1 -0
  95. package/build/lib/schema/cli-args.d.ts +19 -0
  96. package/build/lib/schema/cli-args.d.ts.map +1 -0
  97. package/build/lib/schema/cli-args.js +220 -0
  98. package/build/lib/schema/cli-args.js.map +1 -0
  99. package/build/lib/schema/cli-transformers.d.ts +5 -0
  100. package/build/lib/schema/cli-transformers.d.ts.map +1 -0
  101. package/build/lib/schema/cli-transformers.js +124 -0
  102. package/build/lib/schema/cli-transformers.js.map +1 -0
  103. package/build/lib/schema/index.d.ts +3 -0
  104. package/build/lib/schema/index.d.ts.map +1 -0
  105. package/build/lib/schema/index.js +19 -0
  106. package/build/lib/schema/index.js.map +1 -0
  107. package/build/lib/schema/keywords.d.ts +24 -0
  108. package/build/lib/schema/keywords.d.ts.map +1 -0
  109. package/build/lib/schema/keywords.js +128 -0
  110. package/build/lib/schema/keywords.js.map +1 -0
  111. package/build/lib/schema/schema.d.ts +260 -0
  112. package/build/lib/schema/schema.d.ts.map +1 -0
  113. package/build/lib/schema/schema.js +640 -0
  114. package/build/lib/schema/schema.js.map +1 -0
  115. package/build/lib/utils.d.ts +276 -0
  116. package/build/lib/utils.d.ts.map +1 -0
  117. package/build/lib/utils.js +372 -192
  118. package/build/lib/utils.js.map +1 -0
  119. package/build/types/cli.d.ts +134 -0
  120. package/build/types/cli.d.ts.map +1 -0
  121. package/build/types/cli.js +3 -0
  122. package/build/types/cli.js.map +1 -0
  123. package/build/types/index.d.ts +15 -0
  124. package/build/types/index.d.ts.map +1 -0
  125. package/build/types/index.js +19 -0
  126. package/build/types/index.js.map +1 -0
  127. package/build/types/manifest/base.d.ts +135 -0
  128. package/build/types/manifest/base.d.ts.map +1 -0
  129. package/build/types/manifest/base.js +3 -0
  130. package/build/types/manifest/base.js.map +1 -0
  131. package/build/types/manifest/index.d.ts +21 -0
  132. package/build/types/manifest/index.d.ts.map +1 -0
  133. package/build/types/manifest/index.js +42 -0
  134. package/build/types/manifest/index.js.map +1 -0
  135. package/build/types/manifest/v3.d.ts +139 -0
  136. package/build/types/manifest/v3.d.ts.map +1 -0
  137. package/build/types/manifest/v3.js +3 -0
  138. package/build/types/manifest/v3.js.map +1 -0
  139. package/build/types/manifest/v4.d.ts +139 -0
  140. package/build/types/manifest/v4.d.ts.map +1 -0
  141. package/build/types/manifest/v4.js +3 -0
  142. package/build/types/manifest/v4.js.map +1 -0
  143. package/driver.d.ts +1 -0
  144. package/driver.js +14 -0
  145. package/index.js +11 -0
  146. package/lib/appium.js +545 -188
  147. package/lib/cli/args.js +275 -407
  148. package/lib/cli/driver-command.js +132 -24
  149. package/lib/cli/extension-command.js +751 -272
  150. package/lib/cli/extension.js +38 -19
  151. package/lib/cli/parser.js +267 -95
  152. package/lib/cli/plugin-command.js +122 -22
  153. package/lib/cli/utils.js +24 -10
  154. package/lib/config-file.js +220 -0
  155. package/lib/config.js +243 -132
  156. package/lib/constants.js +79 -0
  157. package/lib/extension/driver-config.js +247 -0
  158. package/lib/extension/extension-config.js +709 -0
  159. package/lib/extension/index.js +116 -0
  160. package/lib/extension/manifest-migrations.js +136 -0
  161. package/lib/extension/manifest.js +580 -0
  162. package/lib/extension/package-changed.js +64 -0
  163. package/lib/extension/plugin-config.js +112 -0
  164. package/lib/grid-register.js +49 -35
  165. package/lib/logger.js +1 -2
  166. package/lib/logsink.js +59 -36
  167. package/lib/main.js +392 -104
  168. package/lib/schema/arg-spec.js +229 -0
  169. package/lib/schema/cli-args.js +241 -0
  170. package/lib/schema/cli-transformers.js +119 -0
  171. package/lib/schema/index.js +2 -0
  172. package/lib/schema/keywords.js +136 -0
  173. package/lib/schema/schema.js +725 -0
  174. package/lib/utils.js +310 -89
  175. package/package.json +84 -84
  176. package/plugin.d.ts +1 -0
  177. package/plugin.js +13 -0
  178. package/scripts/autoinstall-extensions.js +243 -0
  179. package/support.d.ts +1 -0
  180. package/support.js +13 -0
  181. package/tsconfig.json +25 -0
  182. package/types/cli.ts +193 -0
  183. package/types/index.ts +20 -0
  184. package/types/manifest/README.md +30 -0
  185. package/types/manifest/base.ts +158 -0
  186. package/types/manifest/index.ts +28 -0
  187. package/types/manifest/v3.ts +161 -0
  188. package/types/manifest/v4.ts +161 -0
  189. package/CHANGELOG.md +0 -3669
  190. package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
  191. package/build/lib/cli/argparse-actions.js +0 -104
  192. package/build/lib/cli/npm.js +0 -207
  193. package/build/lib/cli/parser-helpers.js +0 -93
  194. package/build/lib/driver-config.js +0 -77
  195. package/build/lib/drivers.js +0 -99
  196. package/build/lib/extension-config.js +0 -253
  197. package/build/lib/plugin-config.js +0 -59
  198. package/build/lib/plugins.js +0 -16
  199. package/build/postinstall.js +0 -90
  200. package/lib/cli/argparse-actions.js +0 -77
  201. package/lib/cli/npm.js +0 -183
  202. package/lib/cli/parser-helpers.js +0 -91
  203. package/lib/driver-config.js +0 -46
  204. package/lib/drivers.js +0 -84
  205. package/lib/extension-config.js +0 -209
  206. package/lib/plugin-config.js +0 -34
  207. package/lib/plugins.js +0 -11
  208. package/postinstall.js +0 -71
package/lib/cli/args.js CHANGED
@@ -1,430 +1,298 @@
1
- import { DEFAULT_BASE_PATH } from 'appium-base-driver';
2
- import { parseSecurityFeatures, parseDefaultCaps, parsePluginNames, parseInstallTypes } from './parser-helpers';
3
- import { INSTALL_TYPES, DEFAULT_APPIUM_HOME, DRIVER_TYPE, PLUGIN_TYPE } from '../extension-config';
4
- import { DEFAULT_CAPS_ARG, StoreDeprecatedDefaultCapabilityAction } from './argparse-actions';
5
-
1
+ import _ from 'lodash';
2
+ import {
3
+ DRIVER_TYPE,
4
+ PLUGIN_TYPE,
5
+ EXT_SUBCOMMAND_INSTALL,
6
+ EXT_SUBCOMMAND_LIST,
7
+ EXT_SUBCOMMAND_RUN,
8
+ EXT_SUBCOMMAND_UNINSTALL,
9
+ EXT_SUBCOMMAND_UPDATE,
10
+ } from '../constants';
11
+ import {INSTALL_TYPES} from '../extension/extension-config';
12
+ import {toParserArgs} from '../schema/cli-args';
6
13
  const DRIVER_EXAMPLE = 'xcuitest';
7
14
  const PLUGIN_EXAMPLE = 'find_by_image';
8
- const USE_ALL_PLUGINS = 'all';
9
-
10
- // sharedArgs will be added to every subcommand
11
- const sharedArgs = [
12
- [['-ah', '--home', '--appium-home'], {
13
- required: false,
14
- default: process.env.APPIUM_HOME || DEFAULT_APPIUM_HOME,
15
- help: 'The path to the directory where Appium will keep installed drivers, plugins, and any other metadata necessary for its operation',
16
- dest: 'appiumHome',
17
- }],
18
-
19
- [['--log-filters'], {
20
- dest: 'logFilters',
21
- default: null,
22
- required: false,
23
- action: 'store_true',
24
- help: 'Set the full path to a JSON file containing one or more log filtering rules',
25
- }],
26
- ];
27
-
28
- const serverArgs = [
29
- [['--shell'], {
30
- required: false,
31
- default: null,
32
- help: 'Enter REPL mode',
33
- action: 'store_true',
34
- dest: 'shell',
35
- }],
36
-
37
- [['--plugins'], {
38
- required: false,
39
- default: [],
40
- help: `A comma-separated list of installed plugin names that should be active for this ` +
41
- `server. To activate all plugins, you can use the single string "${USE_ALL_PLUGINS}" ` +
42
- `as the value (e.g. --plugins=${USE_ALL_PLUGINS})`,
43
- type: parsePluginNames,
44
- dest: 'plugins',
45
- }],
46
-
47
- [['--allow-cors'], {
48
- required: false,
49
- default: false,
50
- action: 'store_true',
51
- help: 'Whether the Appium server should allow web browser connections from any host',
52
- dest: 'allowCors',
53
- }],
54
-
55
- [['--reboot'], {
56
- default: false,
57
- dest: 'reboot',
58
- action: StoreDeprecatedDefaultCapabilityAction,
59
- required: false,
60
- help: '(Android-only) reboot emulator after each session and kill it at the end',
61
- }],
62
-
63
- [['-a', '--address'], {
64
- default: '0.0.0.0',
65
- required: false,
66
- help: 'IP Address to listen on',
67
- dest: 'address',
68
- }],
69
-
70
- [['-p', '--port'], {
71
- default: 4723,
72
- required: false,
73
- type: 'int',
74
- help: 'port to listen on',
75
- dest: 'port',
76
- }],
77
-
78
- [['-pa', '--base-path'], {
79
- required: false,
80
- default: DEFAULT_BASE_PATH,
81
- dest: 'basePath',
82
- help: 'Base path to use as the prefix for all webdriver routes running ' +
83
- `on this server`
84
- }],
85
-
86
- [['-ka', '--keep-alive-timeout'], {
87
- required: false,
88
- default: null,
89
- dest: 'keepAliveTimeout',
90
- type: 'int',
91
- help: 'Number of seconds the Appium server should apply as both the keep-alive timeout ' +
92
- 'and the connection timeout for all requests. Defaults to 600 (10 minutes).'
93
- }],
94
-
95
- [['-ca', '--callback-address'], {
96
- required: false,
97
- dest: 'callbackAddress',
98
- default: null,
99
- help: 'callback IP Address (default: same as --address)',
100
- }],
101
-
102
- [['-cp', '--callback-port'], {
103
- required: false,
104
- dest: 'callbackPort',
105
- default: null,
106
- type: 'int',
107
- help: 'callback port (default: same as port)',
108
- }],
109
-
110
- [['--session-override'], {
111
- default: false,
112
- dest: 'sessionOverride',
113
- action: 'store_true',
114
- required: false,
115
- help: 'Enables session override (clobbering)',
116
- }],
117
-
118
- [['-g', '--log'], {
119
- default: null,
120
- dest: 'logFile',
121
- required: false,
122
- help: 'Also send log output to this file',
123
- }],
124
-
125
- [['--log-level'], {
126
- choices: [
127
- 'info', 'info:debug', 'info:info', 'info:warn', 'info:error',
128
- 'warn', 'warn:debug', 'warn:info', 'warn:warn', 'warn:error',
129
- 'error', 'error:debug', 'error:info', 'error:warn', 'error:error',
130
- 'debug', 'debug:debug', 'debug:info', 'debug:warn', 'debug:error',
131
- ],
132
- default: 'debug',
133
- dest: 'loglevel',
134
- required: false,
135
- help: 'log level; default (console[:file]): debug[:debug]',
136
- }],
137
-
138
- [['--log-timestamp'], {
139
- default: false,
140
- required: false,
141
- help: 'Show timestamps in console output',
142
- action: 'store_true',
143
- dest: 'logTimestamp',
144
- }],
145
-
146
- [['--local-timezone'], {
147
- default: false,
148
- required: false,
149
- help: 'Use local timezone for timestamps',
150
- action: 'store_true',
151
- dest: 'localTimezone',
152
- }],
153
15
 
154
- [['--log-no-colors'], {
155
- default: false,
156
- required: false,
157
- help: 'Do not use colors in console output',
158
- action: 'store_true',
159
- dest: 'logNoColors',
160
- }],
16
+ /**
17
+ * This is necessary because we pass the array into `argparse`. `argparse` is bad and mutates things. We don't want that.
18
+ * Bad `argparse`! Bad!
19
+ */
20
+ const INSTALL_TYPES_ARRAY = [...INSTALL_TYPES];
161
21
 
162
- [['-G', '--webhook'], {
163
- default: null,
164
- required: false,
165
- dest: 'webhook',
166
- help: 'Also send log output to this HTTP listener, for example localhost:9876',
167
- }],
168
-
169
- [['--nodeconfig'], {
170
- required: false,
171
- default: null,
172
- dest: 'nodeconfig',
173
- help: 'Configuration JSON file to register appium with selenium grid',
174
- }],
175
-
176
- [['--chromedriver-port'], {
177
- default: null,
178
- dest: 'chromeDriverPort',
179
- required: false,
180
- action: StoreDeprecatedDefaultCapabilityAction,
181
- type: 'int',
182
- help: 'Port upon which ChromeDriver will run. If not given, Android driver will pick a random available port.',
183
- }],
184
-
185
- [['--chromedriver-executable'], {
186
- default: null,
187
- dest: 'chromedriverExecutable',
188
- action: StoreDeprecatedDefaultCapabilityAction,
189
- required: false,
190
- help: 'ChromeDriver executable full path',
191
- }],
192
-
193
- [['--show-config'], {
194
- default: false,
195
- dest: 'showConfig',
196
- action: 'store_true',
197
- required: false,
198
- help: 'Show info about the appium server configuration and exit',
199
- }],
200
-
201
- [['--no-perms-check'], {
202
- default: false,
203
- dest: 'noPermsCheck',
204
- action: 'store_true',
205
- required: false,
206
- help: 'Bypass Appium\'s checks to ensure we can read/write necessary files',
207
- }],
208
-
209
- [['--strict-caps'], {
210
- default: false,
211
- dest: 'enforceStrictCaps',
212
- action: 'store_true',
213
- required: false,
214
- help: 'Cause sessions to fail if desired caps are sent in that Appium ' +
215
- 'does not recognize as valid for the selected device',
216
- }],
217
-
218
- [['--tmp'], {
219
- default: null,
220
- dest: 'tmpDir',
221
- required: false,
222
- help: 'Absolute path to directory Appium can use to manage temporary ' +
223
- 'files, like built-in iOS apps it needs to move around. On *nix/Mac ' +
224
- 'defaults to /tmp, on Windows defaults to C:\\Windows\\Temp',
225
- }],
226
-
227
- [['--trace-dir'], {
228
- default: null,
229
- dest: 'traceDir',
230
- required: false,
231
- help: 'Absolute path to directory Appium use to save ios instruments ' +
232
- 'traces, defaults to <tmp dir>/appium-instruments',
233
- }],
234
-
235
- [['--debug-log-spacing'], {
236
- dest: 'debugLogSpacing',
237
- default: false,
238
- action: 'store_true',
239
- required: false,
240
- help: 'Add exaggerated spacing in logs to help with visual inspection',
241
- }],
242
-
243
- [['--suppress-adb-kill-server'], {
244
- dest: 'suppressKillServer',
245
- default: false,
246
- action: StoreDeprecatedDefaultCapabilityAction,
247
- required: false,
248
- help: '(Android-only) If set, prevents Appium from killing the adb server instance',
249
- }],
250
-
251
- [['--long-stacktrace'], {
252
- dest: 'longStacktrace',
253
- default: false,
254
- required: false,
255
- action: 'store_true',
256
- help: 'Add long stack traces to log entries. Recommended for debugging only.',
257
- }],
258
-
259
- [['--webkit-debug-proxy-port'], {
260
- default: 27753,
261
- dest: 'webkitDebugProxyPort',
262
- action: StoreDeprecatedDefaultCapabilityAction,
263
- required: false,
264
- type: 'int',
265
- help: '(IOS-only) Local port used for communication with ios-webkit-debug-proxy'
266
- }],
267
-
268
- [['--webdriveragent-port'], {
269
- default: 8100,
270
- dest: 'wdaLocalPort',
271
- action: StoreDeprecatedDefaultCapabilityAction,
272
- required: false,
273
- type: 'int',
274
- help: '(IOS-only, XCUITest-only) Local port used for communication with WebDriverAgent'
275
- }],
276
-
277
- [['-dc', DEFAULT_CAPS_ARG], {
278
- dest: 'defaultCapabilities',
279
- default: {},
280
- type: parseDefaultCaps,
281
- required: false,
282
- help: 'Set the default desired capabilities, which will be set on each ' +
283
- 'session unless overridden by received capabilities. For example: ' +
284
- '[ \'{"app": "myapp.app", "deviceName": "iPhone Simulator"}\' ' +
285
- '| /path/to/caps.json ]'
286
- }],
287
-
288
- [['--relaxed-security'], {
289
- default: false,
290
- dest: 'relaxedSecurityEnabled',
291
- action: 'store_true',
292
- required: false,
293
- help: 'Disable additional security checks, so it is possible to use some advanced features, provided ' +
294
- 'by drivers supporting this option. Only enable it if all the ' +
295
- 'clients are in the trusted network and it\'s not the case if a client could potentially ' +
296
- 'break out of the session sandbox. Specific features can be overridden by ' +
297
- 'using the --deny-insecure flag',
298
- }],
299
-
300
- [['--allow-insecure'], {
301
- dest: 'allowInsecure',
302
- default: [],
303
- type: parseSecurityFeatures,
304
- required: false,
305
- help: 'Set which insecure features are allowed to run in this server\'s sessions. ' +
306
- 'Features are defined on a driver level; see documentation for more details. ' +
307
- 'This should be either a comma-separated list of feature names, or a path to ' +
308
- 'a file where each feature name is on a line. Note that features defined via ' +
309
- '--deny-insecure will be disabled, even if also listed here.',
310
- }],
311
-
312
- [['--deny-insecure'], {
313
- dest: 'denyInsecure',
314
- default: [],
315
- type: parseSecurityFeatures,
316
- required: false,
317
- help: 'Set which insecure features are not allowed to run in this server\'s sessions. ' +
318
- 'Features are defined on a driver level; see documentation for more details. ' +
319
- 'This should be either a comma-separated list of feature names, or a path to ' +
320
- 'a file where each feature name is on a line. Features listed here will not be ' +
321
- 'enabled even if also listed in --allow-insecure, and even if --relaxed-security ' +
322
- 'is turned on. For example: execute_driver_script,adb_shell',
323
- }],
324
- ];
22
+ /** @type {Set<ExtensionType>} */
23
+ const EXTENSION_TYPES = new Set([DRIVER_TYPE, PLUGIN_TYPE]);
325
24
 
326
25
  // this set of args works for both drivers and plugins ('extensions')
327
- const globalExtensionArgs = [
328
- [['--json'], {
329
- required: false,
330
- default: false,
331
- action: 'store_true',
332
- help: 'Use JSON for output format',
333
- dest: 'json'
334
- }]
335
- ];
336
-
337
- const extensionArgs = {[DRIVER_TYPE]: {}, [PLUGIN_TYPE]: {}};
338
-
339
- function makeListArgs (type) {
340
- return [
341
- ...globalExtensionArgs,
342
- [['--installed'], {
26
+ /** @type {ArgumentDefinitions} */
27
+ const globalExtensionArgs = new Map([
28
+ [
29
+ ['--json'],
30
+ {
343
31
  required: false,
344
32
  default: false,
345
33
  action: 'store_true',
346
- help: `List only installed ${type}s`,
347
- dest: 'showInstalled'
348
- }],
349
- [['--updates'], {
350
- required: false,
351
- default: false,
352
- action: 'store_true',
353
- help: 'Show information about newer versions',
354
- dest: 'showUpdates'
355
- }]
356
- ];
34
+ help: 'Use JSON for output format',
35
+ dest: 'json',
36
+ },
37
+ ],
38
+ ]);
39
+
40
+ /**
41
+ * Builds a Record of extension types to a Record of subcommands to their argument definitions
42
+ */
43
+ const getExtensionArgs = _.memoize(function getExtensionArgs() {
44
+ const extensionArgs = {};
45
+ for (const type of EXTENSION_TYPES) {
46
+ extensionArgs[type] = {
47
+ [EXT_SUBCOMMAND_LIST]: makeListArgs(type),
48
+ [EXT_SUBCOMMAND_INSTALL]: makeInstallArgs(type),
49
+ [EXT_SUBCOMMAND_UNINSTALL]: makeUninstallArgs(type),
50
+ [EXT_SUBCOMMAND_UPDATE]: makeUpdateArgs(type),
51
+ [EXT_SUBCOMMAND_RUN]: makeRunArgs(type),
52
+ };
53
+ }
54
+ return /** @type {Record<ExtensionType, Record<import('appium/types').CliExtensionSubcommand,ArgumentDefinitions>>} */ (
55
+ extensionArgs
56
+ );
57
+ });
58
+
59
+ /**
60
+ * Makes the opts for the `list` subcommand for each extension type.
61
+ * @param {ExtensionType} type
62
+ * @returns {ArgumentDefinitions}
63
+ */
64
+ function makeListArgs(type) {
65
+ return new Map([
66
+ ...globalExtensionArgs,
67
+ [
68
+ ['--installed'],
69
+ {
70
+ required: false,
71
+ default: false,
72
+ action: 'store_true',
73
+ help: `List only installed ${type}s`,
74
+ dest: 'showInstalled',
75
+ },
76
+ ],
77
+ [
78
+ ['--updates'],
79
+ {
80
+ required: false,
81
+ default: false,
82
+ action: 'store_true',
83
+ help: 'Show information about newer versions',
84
+ dest: 'showUpdates',
85
+ },
86
+ ],
87
+ [
88
+ ['--verbose'],
89
+ {
90
+ required: false,
91
+ default: false,
92
+ action: 'store_true',
93
+ help: 'Show more information about each extension',
94
+ dest: 'verbose',
95
+ },
96
+ ],
97
+ ]);
357
98
  }
358
99
 
359
-
360
- function makeInstallArgs (type) {
361
- return [
100
+ /**
101
+ * Makes the opts for the `install` subcommand for each extension type
102
+ * @param {ExtensionType} type
103
+ * @returns {ArgumentDefinitions}
104
+ */
105
+ function makeInstallArgs(type) {
106
+ return new Map([
362
107
  ...globalExtensionArgs,
363
- [[type], {
364
- type: 'str',
365
- help: `Name of the ${type} to install, for example: ` +
366
- type === DRIVER_TYPE ? DRIVER_EXAMPLE : PLUGIN_EXAMPLE,
367
- }],
368
- [['--source'], {
369
- required: false,
370
- default: null,
371
- type: parseInstallTypes,
372
- help: `Where to look for the ${type} if it is not one of Appium's verified ` +
373
- `${type}s. Possible values: ${JSON.stringify(INSTALL_TYPES)}`,
374
- dest: 'installType'
375
- }],
376
- [['--package'], {
377
- required: false,
378
- default: null,
379
- type: 'str',
380
- help: `If installing from Git or GitHub, the package name, as defined in the plugin's ` +
381
- `package.json file in the "name" field, cannot be determined automatically, and ` +
382
- `should be reported here, otherwise the install will probably fail.`,
383
- dest: 'packageName',
384
- }],
385
- ];
108
+ [
109
+ [type],
110
+ {
111
+ type: 'str',
112
+ help:
113
+ `Name of the ${type} to install, for example: ` + type === DRIVER_TYPE
114
+ ? DRIVER_EXAMPLE
115
+ : PLUGIN_EXAMPLE,
116
+ },
117
+ ],
118
+ [
119
+ ['--source'],
120
+ {
121
+ required: false,
122
+ default: null,
123
+ choices: INSTALL_TYPES_ARRAY,
124
+ help:
125
+ `Where to look for the ${type} if it is not one of Appium's verified ` +
126
+ `${type}s. Possible values: ${INSTALL_TYPES_ARRAY.join(', ')}`,
127
+ dest: 'installType',
128
+ },
129
+ ],
130
+ [
131
+ ['--package'],
132
+ {
133
+ required: false,
134
+ default: null,
135
+ type: 'str',
136
+ help:
137
+ `If installing from Git or GitHub, the package name, as defined in the plugin's ` +
138
+ `package.json file in the "name" field, cannot be determined automatically, and ` +
139
+ `should be reported here, otherwise the install will probably fail.`,
140
+ dest: 'packageName',
141
+ },
142
+ ],
143
+ ]);
386
144
  }
387
145
 
388
- function makeUninstallArgs (type) {
389
- return [
146
+ /**
147
+ * Makes the opts for the `uninstall` subcommand for each extension type
148
+ * @param {ExtensionType} type
149
+ * @returns {ArgumentDefinitions}
150
+ */
151
+ function makeUninstallArgs(type) {
152
+ return new Map([
390
153
  ...globalExtensionArgs,
391
- [[type], {
392
- type: 'str',
393
- help: 'Name of the driver to uninstall, for example: ' +
394
- type === DRIVER_TYPE ? DRIVER_EXAMPLE : PLUGIN_EXAMPLE
395
- }],
396
- ];
154
+ [
155
+ [type],
156
+ {
157
+ type: 'str',
158
+ help:
159
+ 'Name of the driver to uninstall, for example: ' + type === DRIVER_TYPE
160
+ ? DRIVER_EXAMPLE
161
+ : PLUGIN_EXAMPLE,
162
+ },
163
+ ],
164
+ ]);
397
165
  }
398
166
 
399
- function makeUpdateArgs (type) {
400
- return [
167
+ /**
168
+ * Makes the opts for the `update` subcommand for each extension type
169
+ * @param {ExtensionType} type
170
+ * @returns {ArgumentDefinitions}
171
+ */
172
+ function makeUpdateArgs(type) {
173
+ return new Map([
401
174
  ...globalExtensionArgs,
402
- [[type], {
403
- type: 'str',
404
- help: `Name of the ${type} to update, or the word "installed" to update all installed ` +
175
+ [
176
+ [type],
177
+ {
178
+ type: 'str',
179
+ help:
180
+ `Name of the ${type} to update, or the word "installed" to update all installed ` +
405
181
  `${type}s. To see available updates, run "appium ${type} list --installed --updates". ` +
406
- 'For example: ' + type === DRIVER_TYPE ? DRIVER_EXAMPLE : PLUGIN_EXAMPLE,
407
- }],
408
- [['--unsafe'], {
409
- required: false,
410
- default: false,
411
- action: 'store_true',
412
- help: `Include updates that might have a new major revision, and potentially include ` +
413
- `breaking changes`,
414
- }],
415
- ];
182
+ 'For example: ' +
183
+ type ===
184
+ DRIVER_TYPE
185
+ ? DRIVER_EXAMPLE
186
+ : PLUGIN_EXAMPLE,
187
+ },
188
+ ],
189
+ [
190
+ ['--unsafe'],
191
+ {
192
+ required: false,
193
+ default: false,
194
+ action: 'store_true',
195
+ help:
196
+ `Include updates that might have a new major revision, and potentially include ` +
197
+ `breaking changes`,
198
+ },
199
+ ],
200
+ ]);
201
+ }
202
+
203
+ /**
204
+ * Makes the opts for the `run` subcommand for each extension type
205
+ * @param {ExtensionType} type
206
+ * @returns {ArgumentDefinitions}
207
+ */
208
+ function makeRunArgs(type) {
209
+ return new Map([
210
+ ...globalExtensionArgs,
211
+ [
212
+ [type],
213
+ {
214
+ type: 'str',
215
+ help:
216
+ `Name of the ${type} to run a script from, for example: ` + type === DRIVER_TYPE
217
+ ? DRIVER_EXAMPLE
218
+ : PLUGIN_EXAMPLE,
219
+ },
220
+ ],
221
+ [
222
+ ['scriptName'],
223
+ {
224
+ default: null,
225
+ type: 'str',
226
+ help:
227
+ `Name of the script to run from the ${type}. The script name must be a key ` +
228
+ `inside the "appium.scripts" field inside the ${type}'s "package.json" file`,
229
+ },
230
+ ],
231
+ ]);
416
232
  }
417
233
 
418
- for (const type of [DRIVER_TYPE, PLUGIN_TYPE]) {
419
- extensionArgs[type].list = makeListArgs(type);
420
- extensionArgs[type].install = makeInstallArgs(type);
421
- extensionArgs[type].uninstall = makeUninstallArgs(type);
422
- extensionArgs[type].update = makeUpdateArgs(type);
234
+ /**
235
+ * Derives the options for the `server` command from the schema, and adds the arguments
236
+ * which are disallowed in the config file.
237
+ * @returns {ArgumentDefinitions}
238
+ */
239
+ function getServerArgs() {
240
+ return new Map([...toParserArgs(), ...serverArgsDisallowedInConfig]);
423
241
  }
424
242
 
425
- export {
426
- sharedArgs,
427
- serverArgs,
428
- extensionArgs,
429
- USE_ALL_PLUGINS,
430
- };
243
+ /**
244
+ * These don't make sense in the context of a config file for obvious reasons.
245
+ * @type {ArgumentDefinitions}
246
+ */
247
+ const serverArgsDisallowedInConfig = new Map([
248
+ [
249
+ ['--shell'],
250
+ {
251
+ required: false,
252
+ help: 'Enter REPL mode',
253
+ action: 'store_const',
254
+ const: true,
255
+ dest: 'shell',
256
+ },
257
+ ],
258
+ [
259
+ ['--show-build-info'],
260
+ {
261
+ dest: 'showBuildInfo',
262
+ action: 'store_const',
263
+ const: true,
264
+ required: false,
265
+ help: 'Show info about the Appium build and exit',
266
+ },
267
+ ],
268
+ [
269
+ ['--show-config'],
270
+ {
271
+ dest: 'showConfig',
272
+ action: 'store_const',
273
+ const: true,
274
+ required: false,
275
+ help: 'Show the current Appium configuration and exit',
276
+ },
277
+ ],
278
+ [
279
+ ['--config'],
280
+ {
281
+ dest: 'configFile',
282
+ type: 'str',
283
+ required: false,
284
+ help: 'Explicit path to Appium configuration file',
285
+ },
286
+ ],
287
+ ]);
288
+
289
+ export {getServerArgs, getExtensionArgs};
290
+
291
+ /**
292
+ * @typedef {import('@appium/types').ExtensionType} ExtensionType
293
+ */
294
+
295
+ /**
296
+ * A tuple of argument aliases and argument options
297
+ * @typedef {Map<[name: string]|[name: string, alias: string],import('argparse').ArgumentOptions>} ArgumentDefinitions
298
+ */