Skip to content

Commit

Permalink
added better handling for validate responses
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisfjones committed Dec 7, 2011
1 parent 509ae1e commit 04d1dd9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
29 changes: 21 additions & 8 deletions lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coffin",
"version": "0.0.4",
"version": "0.0.5",
"description": "Coffee dsl for aws cloudformation",
"keywords": ["coffeescript", "coffee-script", "aws", "cloudformation"],
"author": "Chris Jones",
Expand Down
19 changes: 14 additions & 5 deletions src/command.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,22 @@ generateOutputFileName = (source) ->

buildCfnPath = ->
cfnHome = commander['cfn-home'] || process.env.AWS_CLOUDFORMATION_HOME
return path.normalize "#{cfnHome}/bin"
return path.normalize path.join cfnHome, 'bin'

validateTemplate = (templatePath, callback) =>
validateExec = "cfn-validate-template --template-file #{templatePath}"
exec "#{buildCfnPath()}/#{validateExec}", (err) ->
callback?(if err then 1 else 0)
validateExec = spawn path.join(buildCfnPath(), 'cfn-validate-template'), ['--template-file', templatePath]
errorText = ''
resultText = ''
validateExec.stderr.on 'data', (data) -> errorText += data.toString()
validateExec.stdout.on 'data', (data) -> resultText += data.toString()
validateExec.on 'exit', (code) ->
if code is 0
process.stdout.write "#{checkChar}\n"
process.stdout.write resultText
else
process.stdout.write "#{crossChar}\n"
process.stderr.write errorText
callback?(code)

updateOrCreateStack = (name, templatePath, callback) =>
updateExec = spawn "#{buildCfnPath()}/cfn-update-stack", ['--template-file', templatePath, '--stack-name', name]
Expand Down Expand Up @@ -147,7 +157,6 @@ validateCommand.action (template) ->
tempFileName = generateTempFileName()
writeJsonTemplate compiled, tempFileName, ->
validateTemplate tempFileName, (resultCode) ->
process.stdout.write if resultCode is 0 then "#{checkChar}\n" else "#{crossChar}\n"

stackCommand = commander.command 'stack [name] [template]'
stackCommand.description 'Create or update the named stack using the compiled template. Either an AWS_CLOUDFORMATION_HOME environment variable or a --cfn-home switch is required.'
Expand Down

0 comments on commit 04d1dd9

Please sign in to comment.