Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[api] Improve snapshot commands / api calls

  • Loading branch information...
commit 070d7b9abcb1840358ed4f5012559e12bb359180 1 parent 96c9fee
@indexzero indexzero authored
Showing with 58 additions and 23 deletions.
  1. +17 −2 lib/jitsu/api/snapshots.js
  2. +41 −21 lib/jitsu/commands/snapshots.js
View
19 lib/jitsu/api/snapshots.js
@@ -43,8 +43,23 @@ Snapshots.prototype.list = function (name, callback) {
// Creates a snapshot for the application with `app.name = name` using
// the `*.tgz` package data in `snapshot`.
//
-Snapshots.prototype.create = function (name, snapshot, callback) {
- this._upload(['apps', jitsu.config.username, name, 'snapshots'], 'application/octet-stream', snapshot, callback, function (res, body) {
+Snapshots.prototype.create = function (appName, snapshotName, filename, callback) {
+ var url = ['apps', jitsu.config.username, appName, 'snapshots', snapshotName];
+ this._upload(url, 'application/octet-stream', filename, callback, function (res, body) {
callback(null);
});
+};
+
+//
+// ### function create (name, snapshot, callback)
+// #### @name {string} Name of the application to destroy a snapshot for.
+// #### @callback {function} Continuation to pass control to when complete
+// Destroys a snapshot for the application with `app.name = name` and
+// `snapshot.id === snapshotName`.
+//
+Snapshots.prototype.destroy = function (appName, snapshotName, callback) {
+ var url = ['apps', jitsu.config.username, appName, 'snapshots', snapshotName];
+ this._request('DELETE', url, callback, function (res, body) {
+ callback();
+ });
};
View
62 lib/jitsu/commands/snapshots.js
@@ -17,8 +17,8 @@ snapshots.usage = [
'Valid commands are: ',
'',
'jitsu snapshots create',
- 'jitsu snapshots list <name>',
- 'jitsu snapshots destroy <count>',
+ 'jitsu snapshots list <app-name>',
+ 'jitsu snapshots destroy <app-name>',
'',
'For commands that take a <name> parameter, if no parameter',
'is supplied, jitsu will attempt to read the package.json',
@@ -40,12 +40,12 @@ snapshots.list = function (name, callback) {
}
if (snapshots && snapshots.length > 0) {
- var rows = [['filename', 'created', 'md5']],
+ var rows = [['name', 'created', 'md5']],
colors = ['underline', 'yellow', 'grey'];
snapshots.forEach(function (snap) {
rows.push([
- snap.filename,
+ snap.id,
jitsu.utils.snapshotTime(snap.filename),
snap.md5
]);
@@ -57,7 +57,7 @@ snapshots.list = function (name, callback) {
winston.warn('No snapshots for application ' + name.magenta);
}
- callback();
+ callback(null, snapshots, name);
});
}
@@ -95,18 +95,20 @@ snapshots.create = function (name, callback) {
//
// TODO (indexzero): Ensure `snapshot create ../../` works
//
- jitsu.utils.createPackage(process.cwd(), function (err, pkg, filename) {
- if (!callback) {
- callback = name;
- name = null;
- }
-
- name = name || pkg.name;
- winston.info('Creating snapshot for ' + name.magenta);
- winston.silly('Filename: ' + filename);
- jitsu.snapshots.create(name, filename, function (err, snapshots) {
- winston.info('Done creating snapshot ' + name.magenta);
- return err ? callback(err) : callback();
+ jitsu.prompt.get(['Snapshot name'], function (result) {
+ jitsu.utils.createPackage(process.cwd(), function (err, pkg, filename) {
+ if (!callback) {
+ callback = name;
+ name = null;
+ }
+
+ name = name || pkg.name;
+ winston.info('Creating snapshot for ' + name.magenta);
+ winston.silly('Filename: ' + filename);
+ jitsu.snapshots.create(name, result['snapshot name'], filename, function (err, snapshots) {
+ winston.info('Done creating snapshot ' + name.magenta);
+ return err ? callback(err) : callback();
+ });
});
});
};
@@ -118,18 +120,36 @@ snapshots.create.usage = [
];
//
-// ### function destroy (count, callback)
+// ### function destroy (appName, callback)
// #### @count {string} **optional** Number of snapshots to destroy
// #### @callback {function} Continuation to pass control to when complete.
// Destroys the specified number of snapshots for the application in the current
// directory. If `count` is not supplied one snapshot will be destroyed.
//
-snapshots.destroy = function (count, callback) {
+snapshots.destroy = function (name, callback) {
+ var args = [name];
+
if (!callback) {
- callback = count;
+ callback = name;
+ name = null;
+ args = [];
+ }
+
+ function executeDestroy (err, snapshots, name) {
+ jitsu.prompt.get(['Snapshot'], function (result) {
+ var snapshot = snapshots.filter(function (snap) {
+ return snap.id === result['snapshot'];
+ })[0];
+
+ if (!snapshot) {
+ return callback(new Error('Cannot find snapshot with name: ' + result['snapshot'].magenta), true);
+ }
+
+ jitsu.snapshots.destroy(name, snapshot.id, callback);
+ });
}
- callback(new Error('Sorry: Not implemented yet.'), true);
+ snapshots.list.apply(null, args.concat(executeDestroy));
};
snapshots.destroy.usage = [
Please sign in to comment.
Something went wrong with that request. Please try again.