Skip to content

Commit 2e066de

Browse files
committed
Small refactor of template handling
1 parent a171803 commit 2e066de

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

microplan-init.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,47 +37,43 @@ function _parseInputFromUser (callback) {
3737
.option('-t, --template <location>', 'specify input template location', templateFileLocation.yaml)
3838
.parse(process.argv)
3939

40-
var initArgs = program.args
41-
42-
if (initArgs.length < 1) {
43-
callback('Filename required. Please specify a valid' + suppFileExtns.join('/') + 'template location as argument.', null)
40+
if (program.args.length < 1) {
41+
callback('Please specify a valid filename for plan output.', null)
4442
}
4543

44+
var destFilePath = program.args[0]
45+
4646
if (utils.fileExists(program.template) === false) {
47-
callback('Please specify a valid' + suppFileExtns.join('/') + 'template file location.', null)
47+
callback('Please specify a valid template file location.', null)
4848
}
4949

50-
let fileExt = path.extname(program.template)
50+
var fileExt = path.extname(program.template)
5151

5252
if (suppFileExtns.indexOf(fileExt) === -1) {
53-
callback('File extension not supported. Please use supported file extensions: ' + suppFileExtns.join(', '), null)
53+
callback('Template extension not supported. Please use supported file extensions: ' + suppFileExtns.join(', '), null)
5454
} else {
55-
callback(null, program.template, initArgs)
55+
callback(null, program.template, destFilePath)
5656
}
5757
}
5858

59-
function _getOptsFromUser (templateFilePath, initArgs, callback) {
60-
var destFilePath = initArgs[0]
59+
function _getOptsFromUser (templateFilePath, destFilePath, callback) {
6160
if (utils.fileExists(destFilePath)) {
6261
rl.question('File already exists. Do you want to overwrite this file? [N/y]', function (answer) {
6362
if (userOptsYes.indexOf(answer) === -1) {
6463
callback('Not overwriting the file: ' + destFilePath + '. Create plan file with new name and try again.', null)
6564
}
66-
callback(null, templateFilePath, initArgs)
65+
callback(null, templateFilePath, destFilePath)
6766
})
6867
} else {
69-
callback(null, templateFilePath, initArgs)
68+
callback(null, templateFilePath, destFilePath)
7069
}
7170
}
7271

73-
function _copyTemplateFile (templateFilePath, initArgs, callback) {
74-
var destFilePath = initArgs[0]
75-
initArgs.forEach(function (initArg) {
76-
try {
77-
fs.copySync(templateFilePath, destFilePath)
78-
} catch (err) {
79-
callback(err, 'Error copying to the file: ' + destFilePath)
80-
}
81-
callback(null, 'Plan file copied successfully: ' + destFilePath)
82-
})
72+
function _copyTemplateFile (templateFilePath, destFilePath, callback) {
73+
try {
74+
fs.copySync(templateFilePath, destFilePath)
75+
} catch (err) {
76+
callback(err, 'Error copying to the file: ' + destFilePath)
77+
}
78+
callback(null, 'Plan file copied successfully: ' + destFilePath)
8379
}

0 commit comments

Comments
 (0)