Skip to content

Commit

Permalink
Add -o/--output option.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdado committed Oct 30, 2014
1 parent e75d53f commit 222c04e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ function genFixForFile(file, config) {
return function () {
var content = fs.readFileSync(file).toString()
var fixed = ''
var message = ''

var fmjOptions = commander.indentPref
? fu.merge(config, { indentpref: commander.indentPref })
Expand All @@ -142,11 +143,14 @@ function genFixForFile(file, config) {
printDiff(content, fixed)
} else if (commander.patch) {
createPatch(file, content, fixed)
} else if (commander.output) {
message = ' Saved to ' + path.basename(commander.output)
fs.writeFileSync(path.resolve(commander.output), fixed, 'utf8')
} else {
fs.writeFileSync(file, fixed, 'utf8')
}

console.log('\u2713 ' + path.basename(file) + ' done.')
console.log('\u2713 ' + path.basename(file) + ' done.' + message)

return content === fixed
}
Expand All @@ -157,6 +161,9 @@ function traverseFiles(_, fileName) {

switch (isDir(fullpath)) {
case true:
if (commander.output) {
return []
}
if (shouldIgnorePath(fullpath, _.ignore)) {
return []
}
Expand Down Expand Up @@ -210,6 +217,7 @@ commander
.option('-n, --indent-pref [tabs|spaces]', 'Your indentation preference')
.option('-p, --patch', 'Output a patch file to stdout')
.option('-r, --dry-run', 'Performs a dry-run and shows you a diff')
.option('-o, --output <destination>', 'Specify output to a file')
.option('-s, --silent', 'A useless option')
.parse(process.argv)

Expand Down

0 comments on commit 222c04e

Please sign in to comment.