Permalink
Browse files

Fixed some probs with calais CLI tool.

  • Loading branch information...
1 parent fed041a commit 3c0c1767703b2f767601d6c4ea3cb9874f0cf492 @mcantelon committed Jan 28, 2011
Showing with 29 additions and 12 deletions.
  1. +29 −12 calais.js
View
@@ -7,6 +7,7 @@
*/
var fs = require('fs')
+ , path = require('path')
, Calais = require('./lib/calais').Calais
, argv = require('optimist').argv
, iniparser = require('iniparser')
@@ -30,23 +31,39 @@ iniparser.parse(home + '/.calais', function(err, data) {
? argv['k']
: config.api_key
- if (api_key) {
+ if (!api_key) {
- console.log('K:' + api_key)
- }
- else {
+ var help = ''
+ help += "Please specify an OpenCalais API key using the -k option.\n"
+ help += "A default key may be specified by setting 'api_key' in an ini\n"
+ help += "file at $HOME/.calais."
- console.log('Please specify an OpenCalais API key using the -k option.')
+ console.log(help)
+ process.exit(1)
}
- var contents = fs.readFileSync(argv['_'][0])
+ var file = argv['_'][0]
- var calais = new Calais(api_key, {
- 'cleanResult': true
- })
- calais.set('content', content)
- calais.fetch(function(result) {
- console.log(result)
+ path.exists(file, function(exists) {
+
+ if (exists) {
+
+ var content = fs.readFileSync(file)
+
+ var calais = new Calais(api_key, {
+ 'cleanResult': true
+ })
+ calais.set('content', content)
+
+ calais.fetch(function(result) {
+ console.log(result)
+ })
+ }
+ else {
+
+ console.log("Error: file doesn't exist.")
+ process.exit(1)
+ }
})
}
else {

0 comments on commit 3c0c176

Please sign in to comment.