Add okay_if_exists option to mkcouchdb

This commit is contained in:
Simon Metson 2012-10-30 19:17:55 +00:00
parent b514a1e27e
commit 840b93e7d2
1 changed files with 12 additions and 5 deletions

View File

@ -56,18 +56,25 @@ module.exports = function(grunt) {
}); });
grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() { grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() {
var done, parts, nano, dbname; var done, parts, nano, dbname, _this;
_this = this;
done = this.async(); done = this.async();
parts = urls.parse(this.data.db); parts = urls.parse(this.data.db);
dbname = parts.pathname.replace(/^\//, ''); dbname = parts.pathname.replace(/^\//, '');
try { try {
nano = require('nano')(parts.protocol + '//' + parts.host); nano = require('nano')(parts.protocol + '//' + parts.host);
nano.db.create(dbname, function(err) { nano.db.create(dbname, function(err) {
if (err) { if (_this.data.options && _this.data.options.okay_if_exists) {
if (err){
grunt.log.writeln("Database " + dbname + " exists, skipping");
}
return done(null, null);
} else {
if (err){
grunt.warn(err); grunt.warn(err);
} }
return done(err, null); return done(err, null);
}
}); });
} catch (e) { } catch (e) {
grunt.warn(e); grunt.warn(e);