1
- import * as yargs from 'yargs' ;
2
- import * as clean from '../cmds/clean' ;
3
- import * as start from '../cmds/start' ;
4
- import * as status from '../cmds/status' ;
5
- import * as update from '../cmds/update' ;
6
-
7
- const chrome = {
8
- describe : 'Install or update chromedriver.' ,
9
- default : true
10
- } ;
11
- const gecko = {
12
- describe : 'Install or update geckodriver.' ,
13
- default : true
14
- } ;
15
- const ie = {
16
- describe : 'Install or update ie driver.' ,
17
- default : false
18
- } ;
19
- const ignoreSSL = {
20
- describe : 'Ignore SSL certificates.'
21
- }
22
- const outDir = {
23
- describe : 'Location of output.' ,
24
- default : 'downloads'
25
- } ;
26
- const proxy = {
27
- describe : 'Use a proxy server to download files.'
28
- } ;
29
- const standalone = {
30
- describe : 'Install or update selenium server standalone.' ,
31
- default : true
32
- } ;
33
- const versionsChrome = {
34
- describe : 'The chromedriver version.'
35
- } ;
36
- const versionsGecko = {
37
- describe : 'The geckodriver version.' ,
38
- } ;
39
- const versionsIe = {
40
- describe : 'The ie driver version.'
41
- } ;
42
- const versionsStandalone = {
43
- describe : 'The selenium server standalone version.'
44
- } ;
45
-
46
- yargs
47
- . command ( 'clean' , 'Removes downloaded files from the out_dir' , {
48
- 'out_dir' : outDir
49
- } , ( argv : yargs . Arguments ) => {
50
- clean . handler ( argv ) ;
51
- } )
52
- . command ( 'start' , 'Start up the selenium server.' , {
53
- 'chrome' : chrome ,
54
- 'gecko' : gecko ,
55
- 'ie' : ie ,
56
- 'out_dir' : outDir ,
57
- 'standalone' : standalone ,
58
- 'versions_chrome' : versionsChrome ,
59
- 'versions_gecko' : versionsGecko ,
60
- 'versions_ie' : versionsIe ,
61
- 'versions_standalone' : versionsStandalone ,
62
- } , ( argv : yargs . Arguments ) => {
63
- start . handler ( argv ) ;
64
- } )
65
- . command ( 'status' , 'List the current available binaries.' , {
66
- 'out_dir' : outDir
67
- } , ( argv : yargs . Arguments ) => {
68
- status . handler ( argv ) ;
69
- } )
70
- . command ( 'update' , 'Install or update selected binaries.' , {
71
- 'chrome' : chrome ,
72
- 'gecko' : gecko ,
73
- 'ie' : ie ,
74
- 'ignore_ssl' : ignoreSSL ,
75
- 'out_dir' : outDir ,
76
- 'proxy' : proxy ,
77
- 'standalone' : standalone ,
78
- 'versions.chrome' : versionsChrome ,
79
- 'versions.gecko' : versionsGecko ,
80
- 'versions.ie' : versionsIe ,
81
- 'versions.standalone' : versionsStandalone ,
82
- } , ( argv : yargs . Arguments ) => {
83
- update . handler ( argv ) ;
84
- } )
85
- . help ( )
1
+ import * as clean from '../cmds/clean' ;
2
+ import * as start from '../cmds/start' ;
3
+ import * as status from '../cmds/status' ;
4
+ import * as update from '../cmds/update' ;
5
+
6
+ // Not using yargs type definitions due to:
7
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/28061#issuecomment-412365576
8
+ // Although the fix is to cast all my objects into a yargs.Options
9
+ // objects, the error is not obvious to debug if an error occurs.
10
+ const yargs = require ( 'yargs' ) ;
11
+
12
+ const CHROME = 'chrome' ;
13
+ const chromeOption = {
14
+ describe : 'Install or update chromedriver.' ,
15
+ default : true ,
16
+ type : 'boolean'
17
+ } ;
18
+ const GECKO = 'gecko' ;
19
+ const geckoOption = {
20
+ describe : 'Install or update geckodriver.' ,
21
+ default : true ,
22
+ type : 'boolean'
23
+ } ;
24
+ const IEDRIVER = 'iedriver' ;
25
+ const ieOption = {
26
+ describe : 'Install or update ie driver.' ,
27
+ default : false ,
28
+ type : 'boolean'
29
+ } ;
30
+ const IGNORE_SSL = 'ignore_ssl' ;
31
+ const ignoreSSLOption = {
32
+ describe : 'Ignore SSL certificates.' ,
33
+ type : 'boolean'
34
+ } ;
35
+ const OUT_DIR = 'out_dir' ;
36
+ let outDirOption = {
37
+ describe : 'Location of output.' ,
38
+ default : 'downloads' ,
39
+ type : 'string'
40
+ } ;
41
+ const PROXY = 'proxy' ;
42
+ const proxyOption = {
43
+ describe : 'Use a proxy server to download files.' ,
44
+ type : 'string'
45
+ } ;
46
+ const STANDALONE = 'standalone' ;
47
+ const standaloneOption = {
48
+ describe : 'Install or update selenium server standalone.' ,
49
+ default : true ,
50
+ type : 'boolean'
51
+ } ;
52
+ const VERSIONS_CHROME = 'versions.chrome' ;
53
+ const versionsChromeOption = {
54
+ describe : 'The chromedriver version.' ,
55
+ type : 'string'
56
+ } ;
57
+ const VERSIONS_GECKO = 'versions.gecko' ;
58
+ const versionsGeckoOption = {
59
+ describe : 'The geckodriver version.' ,
60
+ type : 'string'
61
+ } ;
62
+ const VERSIONS_IE = 'versions.ie' ;
63
+ const versionsIeOption = {
64
+ describe : 'The ie driver version.' ,
65
+ type : 'string'
66
+ } ;
67
+ const VERSIONS_STANDALONE = 'versions.standalone' ;
68
+ const versionsStandaloneOption = {
69
+ describe : 'The selenium server standalone version.' ,
70
+ type : 'string'
71
+ } ;
72
+
73
+ yargs
74
+ . command ( 'clean' , 'Removes downloaded files from the out_dir.' ,
75
+ ( yargs : any ) => {
76
+ return yargs . option ( OUT_DIR , outDirOption )
77
+ } , ( argv : any ) => {
78
+ clean . handler ( argv ) ;
79
+ } )
80
+ . command ( 'start' , 'Start up the selenium server.' ,
81
+ ( yargs : any ) => {
82
+ return yargs
83
+ . option ( CHROME , chromeOption )
84
+ . option ( GECKO , geckoOption )
85
+ . option ( IEDRIVER , ieOption )
86
+ . option ( OUT_DIR , outDirOption )
87
+ . option ( STANDALONE , standaloneOption )
88
+ . option ( VERSIONS_CHROME , versionsChromeOption )
89
+ . option ( VERSIONS_GECKO , versionsGeckoOption )
90
+ . option ( VERSIONS_IE , versionsIeOption )
91
+ . option ( VERSIONS_STANDALONE , versionsStandaloneOption ) ;
92
+ } , ( argv : any ) => {
93
+ start . handler ( argv ) ;
94
+ } )
95
+ . command ( 'status' , 'List the current available binaries.' ,
96
+ ( yargs : any ) => {
97
+ return yargs . option ( OUT_DIR , outDirOption )
98
+ } , ( argv : any ) => {
99
+ status . handler ( argv ) ;
100
+ } )
101
+ . command ( 'update' , 'Install or update selected binaries.' ,
102
+ ( yargs : any ) => {
103
+ return yargs . option ( OUT_DIR , outDirOption )
104
+ . option ( CHROME , chromeOption )
105
+ . option ( GECKO , geckoOption )
106
+ . option ( IEDRIVER , ieOption )
107
+ . option ( IGNORE_SSL , ignoreSSLOption )
108
+ . option ( OUT_DIR , outDirOption )
109
+ . option ( PROXY , proxyOption )
110
+ . option ( STANDALONE , standaloneOption )
111
+ . option ( VERSIONS_CHROME , versionsChromeOption )
112
+ . option ( VERSIONS_GECKO , versionsGeckoOption )
113
+ . option ( VERSIONS_IE , versionsIeOption )
114
+ . option ( VERSIONS_STANDALONE , versionsStandaloneOption ) ;
115
+ } , ( argv : any ) => {
116
+ update . handler ( argv ) ;
117
+ } )
118
+ . help ( )
86
119
. argv ;
0 commit comments