Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit a6299a4

Browse files
Override RC file with CLI params
1 parent f8f2054 commit a6299a4

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

.topcoderrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"challengeIds": [
3+
"30095545"
4+
],
5+
"username": "TonyJ",
6+
"password": "******"
7+
}

bin/tc-submission-cli.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const logger = require('../src/common/logger')
77
const _ = require('lodash')
88
const fs = require('fs')
99

10+
program
11+
.option('-u, --username <uname>', 'Topcoder username')
12+
.option('-p, --password <password>', 'Topcoder password')
13+
.option('-c, --challengeIds <ids>', 'Comma separated challenge IDs to which submission need to be done')
14+
1015
program.on('--help', () => {
1116
console.log(`\nTopcoder CLI to create a new submission in the challenge
1217
with contents from current directory\n`)
@@ -24,7 +29,7 @@ program.on('--help', () => {
2429

2530
program.parse(process.argv)
2631

27-
uploadSubmissionService.smart(process.cwd())
32+
uploadSubmissionService.smart(process.cwd(), program)
2833
.then(async (responses) => {
2934
const log = {}
3035
_.each(responses, response => {

src/common/helper.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ const schemaForRC = Joi.object({
2020
* Read configuration from given topcoder rc file.
2121
*
2222
* @param {String} filename the name of the rc file
23+
* @param {Object} cliParams CLI params passed to the program
2324
* @returns {Object} the rc object
2425
*/
25-
function readFromRCFile (filename) {
26+
function readFromRCFile (filename, cliParams) {
2627
logger.info('Reading from topcoder rc file...')
2728
const rcObject = JSON.parse(fs.readFileSync(filename).toString())
28-
return validateRCObject(rcObject)
29+
cliParams.challengeIds = cliParams.challengeIds.split(',')
30+
// Override values from RC file with CLI params
31+
return validateRCObject(_.merge(rcObject, _.pick(cliParams, ['username', 'password', 'challengeIds'])))
2932
}
3033

3134
/**
@@ -91,11 +94,11 @@ async function createSubmission (submissionName, submissionData, userId, userNam
9194
logger.info(`Uploading submission on challenge ${challengeId}...`)
9295
const clientConfig = _.pick(config,
9396
['TC_AUTHN_URL', 'TC_AUTHZ_URL', 'TC_CLIENT_ID',
94-
'TC_CLIENT_V2CONNECTION', 'SUBMISSION_API_URL'])
97+
'TC_CLIENT_V2CONNECTION', 'SUBMISSION_API_URL'])
9598
clientConfig['USERNAME'] = userName
9699
clientConfig['PASSWORD'] = password
97100
const submissionApiClient = submissionApi(clientConfig)
98-
101+
99102
const submission = {
100103
memberId: userId,
101104
challengeId: challengeId,
@@ -105,7 +108,7 @@ async function createSubmission (submissionName, submissionData, userId, userNam
105108
data: submissionData
106109
}
107110
}
108-
return await submissionApiClient.createSubmission(submission)
111+
return submissionApiClient.createSubmission(submission)
109112
}
110113

111114
/**

src/services/uploadSubmissionService.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ const logger = require('../common/logger')
1010
* Provide high-level functionality for upload a submission.
1111
* Under current working directory, it archives all files except rc file and
1212
* read rc configuration from the .topcoderrc file.
13-
*
13+
* @param {String} currDir Path to current directory
14+
* @param {Object} cliParams CLI params passed to the program
1415
* @returns {Array} Uploaded submissions
1516
*/
16-
async function smart (prefix) {
17-
const { username, password, challengeIds } = helper.readFromRCFile(path.join(prefix, constants.rc.name))
17+
async function smart (currDir, cliParams) {
18+
const { username, password, challengeIds } = helper.readFromRCFile(path.join(currDir, constants.rc.name), cliParams)
19+
console.log(username)
20+
console.log(password)
21+
console.log(challengeIds)
1822
const userId = await helper.getUserId(username)
1923
const submissionName = helper.submissionNameFromUserId(userId)
20-
const submissionData = helper.archiveCodebase(prefix)
21-
return await basic(submissionName, submissionData, userId, username, password, challengeIds)
24+
const submissionData = helper.archiveCodebase(currDir)
25+
return basic(submissionName, submissionData, userId, username, password, challengeIds)
2226
}
2327

2428
/**

test/unit.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('TC Submission CLI Test', async function () {
3535
testData.userId.admin,
3636
'TonyJ',
3737
'appirio123',
38-
[ testData.challengeId.valid ]
38+
[testData.challengeId.valid]
3939
)
4040
})
4141
it('topcoderrc - It should check if topcoder rc file exists', async function () {

0 commit comments

Comments
 (0)