2
2
process . env . NODE_CONFIG_DIR = `${ __dirname } /../config/`
3
3
4
4
const program = require ( 'commander' )
5
- const uploadSubmissionService = require ( '../src/services/uploadSubmissionService' )
5
+ const submit = require ( '../src/commands/submit' )
6
+ const pay = require ( '../src/commands/pay' )
7
+ const config = require ( '../src/commands/config' )
6
8
const logger = require ( '../src/common/logger' )
7
- const _ = require ( 'lodash' )
8
- const fs = require ( 'fs' )
9
9
10
10
program
11
11
. option ( '-u, --username <uname>' , 'Topcoder username' )
@@ -27,32 +27,36 @@ program.on('--help', () => {
27
27
}` )
28
28
} )
29
29
30
- program . parse ( process . argv )
30
+ program
31
+ . command ( 'submit' )
32
+ . description ( 'Create a challenge submission' )
33
+ . action ( ( ) => {
34
+ try {
35
+ submit ( program )
36
+ } catch ( error ) {
37
+ logger . error ( error . message )
38
+ }
39
+ } )
31
40
32
- uploadSubmissionService . smart ( process . cwd ( ) , program )
33
- . then ( async ( responses ) => {
34
- const log = { }
35
- _ . each ( responses , response => {
36
- const resp = JSON . parse ( response . text )
37
- const submissionId = _ . get ( resp , 'id' , undefined )
38
- const challengeId = _ . get ( resp , 'challengeId' , undefined )
39
- if ( submissionId && challengeId ) {
40
- if ( log [ challengeId ] ) {
41
- log [ challengeId ] . push ( submissionId )
42
- } else {
43
- log [ challengeId ] = [ submissionId ]
44
- }
45
- }
46
- } )
47
- const logTxt = _ . join ( _ . map ( _ . keys ( log ) , key => `challenge_${ key } :\t${ log [ key ] } ` ) , '\n' )
48
- logger . info ( `Uploaded submissions:\n${ logTxt } ` )
49
- await fs . writeFileSync ( 'topcoder-cli.log' ,
50
- `${ Date . now ( ) } :\n${ logTxt } \n\n` ,
51
- { flag : 'a' } )
52
- logger . info ( 'Completed!' )
53
- process . exit ( )
41
+ program
42
+ . command ( 'config' )
43
+ . description ( 'Set up/change globally configured config' )
44
+ . option ( '-l --list' , 'Print out the config of the config file.' )
45
+ . option ( '-a --add <key> <value>' , 'Adds a config to the config file.' )
46
+ . action ( ( ...args ) => {
47
+ try {
48
+ config . handleSubCommand ( args )
49
+ } catch ( error ) {
50
+ logger . error ( error . message )
51
+ }
54
52
} )
55
- . catch ( err => {
56
- logger . error ( err . message )
57
- process . exit ( 1 )
53
+
54
+ program
55
+ . command ( 'pay' )
56
+ . description ( 'Let copilot/managers process private task payments' )
57
+ . option ( '-o --copilot <payment>' , 'copilot payment.' )
58
+ . action ( ( ...args ) => {
59
+ pay . handleCommand ( args )
58
60
} )
61
+
62
+ program . parse ( process . argv )
0 commit comments