1
1
#!/usr/bin/env node
2
2
3
- const program = require ( 'commander' )
3
+ const { Command } = require ( 'commander' )
4
4
const submissionHandler = require ( '../src/commands/submit' )
5
5
const payHandler = require ( '../src/commands/pay' )
6
6
const configHandler = require ( '../src/commands/config' )
7
7
const fetchSubmissionHandler = require ( '../src/commands/fetchSubmissions' )
8
8
const fetchArtifactsHandler = require ( '../src/commands/fetchArtifacts' )
9
9
const logger = require ( '../src/common/logger' )
10
10
11
+ const docs = {
12
+ submit : `\nEither use CLI parameters or Create a file .topcoderrc in JSON ` +
13
+ `format with below details\n` +
14
+ `{\n` +
15
+ ` "memberId": "<Topcoder memberId",\n` +
16
+ ` "challengeIds": [\n` +
17
+ ` "30095545" // at least one item here\n` +
18
+ ` ],\n` +
19
+ ` "username": "<Topcoder username>",\n` +
20
+ ` "password": "<Topcoder password>",\n` +
21
+ ` "m2m": {\n` +
22
+ ` "client_id": "<Client ID for M2M authentication>",\n` +
23
+ ` "client_secret": "<Client Secret for M2M authentication>"\n` +
24
+ ` }\n` +
25
+ `}\n` +
26
+ `and execute command \`topcoder submit\` to submit the contents of ` +
27
+ `current working directory except .topcoderrc file to the challenge.\n` +
28
+ `You'd need either the m2m config or the username and password, but ` +
29
+ `not both.` ,
30
+ 'fetch-submissions' : `\nUse CLI parameters or create a file .topcoderrc in JSON format with below details\n` +
31
+ `{\n` +
32
+ ` "memberId": "<Topcoder memberId",\n` +
33
+ ` "challengeId": "<Topcoder challengeId",\n` +
34
+ ` "submissionId": "<Topcoder submissionId",\n` +
35
+ ` "latest": true,\n` +
36
+ ` "username": "<Topcoder username>",\n` +
37
+ ` "password": "<Topcoder password>",\n` +
38
+ ` "m2m": {\n` +
39
+ ` "client_id": "<Client ID for M2M authentication>",\n` +
40
+ ` "client_secret": "<Client Secret for M2M authentication>"\n` +
41
+ ` }\n` +
42
+ `}\n` +
43
+ `and execute command \`topcoder fetch-submissions\` to fetch submissions ` +
44
+ `for a challenge and save them.\n` +
45
+ `You may specify the m2m config or the username and password config, ` +
46
+ `but not both.\n` +
47
+ `If the submissionId parameter is provided, you must not provide the ` +
48
+ `memberId or the latest parameters.\n` +
49
+ `The challengeId parameter is always required.` ,
50
+ 'fetch-artifacts' : `\nUse CLI parameters or create a file .topcoderrc in JSON format ` +
51
+ `with below details\n` +
52
+ `{\n` +
53
+ ` "submissionId": "<Topcoder submissionId>",\n` +
54
+ ` "legacySubmissionId": "<Topcoder legacySubmissionId>",\n` +
55
+ ` "username": "<Topcoder username>",\n` +
56
+ ` "password": "<Topcoder password>",\n` +
57
+ ` "m2m": {\n` +
58
+ ` "client_id": "<Client ID for M2M authentication>",\n` +
59
+ ` "client_secret": "<Client Secret for M2M authentication>"\n` +
60
+ ` }\n` +
61
+ `}\n` +
62
+ `and execute command \`topcoder fetch-artifacts\` to fetch submissions for` +
63
+ ` a challenge and save them.\n` +
64
+ `You may specify the m2m config or the username and password config, ` +
65
+ `but not both.\n` +
66
+ `If the submissionId parameter is provided, you must not provide the the ` +
67
+ `legacySubmissionId parameters, and vice-versa.`
68
+
69
+ }
70
+
71
+ const program = new Command ( )
72
+
11
73
// Overall help text which will be displayed after usage information
12
74
program . on ( '--help' , ( ) => {
13
75
console . log ( '\nTopcoder CLI to interact with Topcoder systems\n' )
@@ -30,26 +92,7 @@ program
30
92
)
31
93
. option ( '--dev' , 'Points to Topcoder development environment' )
32
94
. on ( '--help' , ( ) => {
33
- console . log (
34
- `\nEither use CLI parameters or Create a file .topcoderrc in JSON ` +
35
- `format with below details\n` +
36
- `{\n` +
37
- ` "memberId": "<Topcoder memberId",\n` +
38
- ` "challengeIds": [\n` +
39
- ` "30095545" // at least one item here\n` +
40
- ` ],\n` +
41
- ` "username": "<Topcoder username>",\n` +
42
- ` "password": "<Topcoder password>",\n` +
43
- ` "m2m": {\n` +
44
- ` "client_id": "<Client ID for M2M authentication>",\n` +
45
- ` "client_secret": "<Client Secret for M2M authentication>"\n` +
46
- ` }\n` +
47
- `}\n` +
48
- `and execute command \`topcoder submit\` to submit the contents of ` +
49
- `current working directory except .topcoderrc file to the challenge.\n` +
50
- `You'd need either the m2m config or the username and password, but ` +
51
- `not both.`
52
- )
95
+ console . log ( docs . submit )
53
96
} )
54
97
. action ( async args => {
55
98
try {
@@ -82,28 +125,7 @@ program
82
125
. option ( '-l, --latest' , 'fetch only the latest submission of each member' )
83
126
. option ( '--dev' , 'Points to Topcoder development environment' )
84
127
. on ( '--help' , ( ) => {
85
- console . log (
86
- `\nUse CLI parameters or create a file .topcoderrc in JSON format with below details\n` +
87
- `{\n` +
88
- ` "memberId": "<Topcoder memberId",\n` +
89
- ` "challengeId": "<Topcoder challengeId",\n` +
90
- ` "submissionId": "<Topcoder submissionId",\n` +
91
- ` "latest": true,\n` +
92
- ` "username": "<Topcoder username>",\n` +
93
- ` "password": "<Topcoder password>",\n` +
94
- ` "m2m": {\n` +
95
- ` "client_id": "<Client ID for M2M authentication>",\n` +
96
- ` "client_secret": "<Client Secret for M2M authentication>"\n` +
97
- ` }\n` +
98
- `}\n` +
99
- `and execute command \`topcoder fetch-submissions\` to fetch submissions ` +
100
- `for a challenge and save them.\n` +
101
- `You may specify the m2m config or the username and password config, ` +
102
- `but not both.\n` +
103
- `If the submissionId parameter is provided, you must not provide the ` +
104
- `memberId or the latest parameters.\n` +
105
- `The challengeId parameter is always required.`
106
- )
128
+ console . log ( docs [ 'fetch-submissions' ] )
107
129
} )
108
130
. action ( async args => {
109
131
try {
@@ -132,24 +154,7 @@ program
132
154
. option ( '--dev' , 'Points to Topcoder development environment' )
133
155
. on ( '--help' , ( ) => {
134
156
console . log (
135
- `\nUse CLI parameters or create a file .topcoderrc in JSON format ` +
136
- `with below details\n` +
137
- `{\n` +
138
- ` "submissionId": "<Topcoder submissionId>",\n` +
139
- ` "legacySubmissionId": "<Topcoder legacySubmissionId>",\n` +
140
- ` "username": "<Topcoder username>",\n` +
141
- ` "password": "<Topcoder password>",\n` +
142
- ` "m2m": {\n` +
143
- ` "client_id": "<Client ID for M2M authentication>",\n` +
144
- ` "client_secret": "<Client Secret for M2M authentication>"\n` +
145
- ` }\n` +
146
- `}\n` +
147
- `and execute command \`topcoder fetch-artifacts\` to fetch submissions for` +
148
- ` a challenge and save them.\n` +
149
- `You may specify the m2m config or the username and password config, ` +
150
- `but not both.\n` +
151
- `If the submissionId parameter is provided, you must not provide the the ` +
152
- `legacySubmissionId parameters, and vice-versa.`
157
+ docs [ 'fetch-artifacts' ]
153
158
)
154
159
} )
155
160
. action ( async args => {
@@ -186,7 +191,7 @@ program
186
191
if ( args . dev ) {
187
192
process . env . NODE_ENV = 'dev'
188
193
}
189
- payHandler . handleCommand ( args )
194
+ payHandler . handleCommand ( program . args )
190
195
} )
191
196
192
197
// error on unknown commands
@@ -199,9 +204,16 @@ program.on('command:*', function () {
199
204
process . exit ( 1 )
200
205
} )
201
206
202
- program . parse ( process . argv )
207
+ /* istanbul ignore next */
208
+ if ( ! module . parent ) {
209
+ program . parse ( process . argv )
210
+ // If the CLI is invoked without any command, display help
211
+ if ( process . argv . length < 3 ) {
212
+ program . help ( )
213
+ }
214
+ }
203
215
204
- // If the CLI is invoked without any command, display help
205
- if ( process . argv . length < 3 ) {
206
- program . help ( )
216
+ module . exports = {
217
+ program ,
218
+ docs
207
219
}
0 commit comments