@@ -4,39 +4,161 @@ const program = 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
+ const fetchSubmissionHandler = require ( '../src/commands/fetchSubmissions' )
8
+ const fetchArtifactsHandler = require ( '../src/commands/fetchArtifacts' )
7
9
const logger = require ( '../src/common/logger' )
8
10
9
11
// Overall help text which will be displayed after usage information
10
12
program . on ( '--help' , ( ) => {
11
- console . log ( ` \nTopcoder CLI to interact with Topcoder systems\n` )
13
+ console . log ( ' \nTopcoder CLI to interact with Topcoder systems\n' )
12
14
} )
13
15
14
16
program
15
17
. command ( 'submit' )
16
- . description ( 'Submit the contents of current working directory to Topcoder challenge(s)' )
17
- . option ( '-u, --username <uname>' , 'Topcoder username' )
18
+ . description (
19
+ 'Submit the contents of current working directory to Topcoder challenge(s)'
20
+ )
21
+ . option ( '-u, --username <username>' , 'Topcoder username' )
18
22
. option ( '-p, --password <password>' , 'Topcoder password' )
19
- . option ( '-m, --memberId <memberid>' , 'Admin submitting on behalf of other member will use the member id' )
20
- . option ( '-c, --challengeIds <ids>' , 'Comma separated challenge IDs to which submission need to be done' )
23
+ . option (
24
+ '-m, --memberId <memberId>' ,
25
+ 'Admin submitting on behalf of other member will use the member id'
26
+ )
27
+ . option (
28
+ '-c, --challengeIds <ids>' ,
29
+ 'Comma separated challenge IDs to which submission need to be done'
30
+ )
21
31
. option ( '--dev' , 'Points to Topcoder development environment' )
22
32
. on ( '--help' , ( ) => {
23
- console . log ( `\nEither use CLI parameters or Create a file .topcoderrc in JSON format with below details
24
- {
25
- "challengeIds": [
26
- "30095545" // at least one item here
27
- ],
28
- "username": "<Topcoder username>",
29
- "password": "<Topcoder password>"
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
+ )
53
+ } )
54
+ . action ( async args => {
55
+ try {
56
+ if ( args . dev ) {
57
+ process . env . NODE_ENV = 'dev'
58
+ }
59
+ await submissionHandler ( program . args [ 0 ] )
60
+ } catch ( error ) {
61
+ logger . error ( error . message )
62
+ }
63
+ } )
64
+
65
+ program
66
+ . command ( 'fetch-submissions' )
67
+ . description ( 'Command to fetch submissions for a challenge and save them.' )
68
+ . option ( '-u, --username <username>' , 'Topcoder username' )
69
+ . option ( '-p, --password <password>' , 'Topcoder password' )
70
+ . option (
71
+ '-c, --challengeId <id>' ,
72
+ 'Challenge ID for submissions to be fetched'
73
+ )
74
+ . option (
75
+ '-u, --userId <id>' ,
76
+ 'Fetch only the submission of for a particular user id'
77
+ )
78
+ . option (
79
+ '-s, --submissionId <id>' ,
80
+ 'Fetch only the submission with a particular submission id'
81
+ )
82
+ . option ( '-l, --latest' , 'fetch only the latest submission of each member' )
83
+ . option ( '--dev' , 'Points to Topcoder development environment' )
84
+ . on ( '--help' , ( ) => {
85
+ console . log (
86
+ `\nUse CLI parameters or create a file .topcoderrc in JSON format with below details` +
87
+ `{\n` +
88
+ ` "userId": "<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
+ `userId or the latest parameters.\n` +
105
+ `The challengeId parameter is always required.`
106
+ )
107
+ } )
108
+ . action ( async args => {
109
+ try {
110
+ if ( args . dev ) {
111
+ process . env . NODE_ENV = 'dev'
112
+ }
113
+ await fetchSubmissionHandler ( program . args [ 0 ] )
114
+ } catch ( error ) {
115
+ logger . error ( error . message )
30
116
}
31
- and execute command \`topcoder submit\` to submit the contents of current working directory except .topcoderrc file to the challenge` )
32
- } ) . action ( ( args ) => {
117
+ } )
118
+
119
+ program
120
+ . command ( 'fetch-artifacts' )
121
+ . description ( 'Command to fetch artifacts for a challenge and save them.' )
122
+ . option ( '-u, --username <username>' , 'Topcoder username' )
123
+ . option ( '-p, --password <password>' , 'Topcoder password' )
124
+ . option (
125
+ '-s, --submissionId <id>' ,
126
+ 'Fetch only the submission with a particular submission id'
127
+ )
128
+ . option (
129
+ '-L, --legacySubmissionId <id>' ,
130
+ 'Fetch only the submission with a particular (legacy) submission id'
131
+ )
132
+ . option ( '--dev' , 'Points to Topcoder development environment' )
133
+ . on ( '--help' , ( ) => {
134
+ 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.`
153
+ )
154
+ } )
155
+ . action ( async args => {
33
156
try {
34
157
if ( args . dev ) {
35
158
process . env . NODE_ENV = 'dev'
36
159
}
37
- submissionHandler ( program . args [ 0 ] )
160
+ await fetchArtifactsHandler ( program . args [ 0 ] )
38
161
} catch ( error ) {
39
- logger . error ( error )
40
162
logger . error ( error . message )
41
163
}
42
164
} )
@@ -47,9 +169,9 @@ program
47
169
. option ( '-l --list' , 'Print the keys in the config file' )
48
170
. option ( '-a --add <key> <value>' , 'Add / Replace a key in the config file.' )
49
171
. option ( '--unset <key>' , 'Removes a key from the config file' )
50
- . action ( ( ...args ) => {
172
+ . action ( async ( ...args ) => {
51
173
try {
52
- configHandler . handleSubCommand ( args )
174
+ await configHandler . handleSubCommand ( args )
53
175
} catch ( error ) {
54
176
logger . error ( error . message )
55
177
}
@@ -60,7 +182,7 @@ program
60
182
. description ( 'Let copilot/managers process private task payments' )
61
183
. option ( '-o --copilot <payment>' , 'copilot payment.' )
62
184
. option ( '--dev' , 'Points to Topcoder development environment' )
63
- . action ( ( ... args ) => {
185
+ . action ( args => {
64
186
if ( args . dev ) {
65
187
process . env . NODE_ENV = 'dev'
66
188
}
@@ -69,7 +191,11 @@ program
69
191
70
192
// error on unknown commands
71
193
program . on ( 'command:*' , function ( ) {
72
- console . error ( 'Invalid command: %s\nEnter topcoder --help for the list of available commands.' , program . args . join ( ' ' ) )
194
+ console . error (
195
+ 'Invalid command: %s\nEnter topcoder --help for the list of available ' +
196
+ 'commands.' ,
197
+ program . args . join ( ' ' )
198
+ )
73
199
process . exit ( 1 )
74
200
} )
75
201
0 commit comments