2014-08-10 15:51:44 -06:00
|
|
|
###
|
2014-09-14 21:04:28 -06:00
|
|
|
Requires http://uncrustify.sourceforge.net/
|
2014-08-10 15:51:44 -06:00
|
|
|
###
|
2014-09-14 21:04:28 -06:00
|
|
|
"use strict"
|
|
|
|
cliBeautify = require("../cli-beautify")
|
|
|
|
cfg = require("./cfg")
|
|
|
|
path = require("path")
|
2014-08-10 15:51:44 -06:00
|
|
|
getCmd = (inputPath, outputPath, options, cb) ->
|
2014-09-14 21:04:28 -06:00
|
|
|
uncrustifyPath = options.uncrustifyPath
|
2014-08-10 15:51:44 -06:00
|
|
|
# console.log('Uncrustify options:', options);
|
2014-09-14 21:04:28 -06:00
|
|
|
# console.log("Uncrustify path: #{uncrustifyPath}")
|
|
|
|
# Complete callback
|
2014-08-10 15:51:44 -06:00
|
|
|
done = (configPath) ->
|
|
|
|
# console.log(configPath);
|
2014-09-14 21:04:28 -06:00
|
|
|
if uncrustifyPath
|
2014-09-14 19:20:27 -06:00
|
|
|
# Use path given by user
|
2014-09-14 21:04:28 -06:00
|
|
|
cmd = "#{uncrustifyPath} -c \"#{configPath}\" -f \"#{inputPath}\" -o \"#{outputPath}\" -l \"#{lang}\""
|
2014-09-14 18:31:37 -06:00
|
|
|
else
|
|
|
|
# Use command available in $PATH
|
2014-09-14 21:04:28 -06:00
|
|
|
cmd = "uncrustify -c \"#{configPath}\" -f \"#{inputPath}\" -o \"#{outputPath}\" -l \"#{lang}\""
|
2014-09-14 19:15:48 -06:00
|
|
|
# console.log(cmd);
|
2014-08-10 15:51:44 -06:00
|
|
|
cb cmd
|
|
|
|
configPath = options.configPath
|
2014-09-14 21:04:28 -06:00
|
|
|
lang = options.languageOverride or "C" # Default is C
|
2014-08-10 15:51:44 -06:00
|
|
|
unless configPath
|
|
|
|
# No custom config path
|
2014-09-14 21:04:28 -06:00
|
|
|
cfg options, (error, cPath) ->
|
2014-08-10 15:51:44 -06:00
|
|
|
throw error if error
|
2014-09-14 21:04:28 -06:00
|
|
|
done cPath
|
2014-08-10 15:51:44 -06:00
|
|
|
else
|
|
|
|
# Has custom config path
|
|
|
|
editor = atom.workspace.getActiveEditor()
|
|
|
|
basePath = path.dirname(editor.getPath())
|
|
|
|
# console.log(basePath);
|
|
|
|
configPath = path.resolve(basePath, configPath)
|
|
|
|
done configPath
|
|
|
|
return
|
|
|
|
module.exports = cliBeautify(getCmd)
|