]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/commitdiff
Add cli
authorJohannes Zellner <johannes@nebulon.de>
Sat, 27 Jun 2015 14:07:34 +0000 (16:07 +0200)
committerJohannes Zellner <johannes@nebulon.de>
Sat, 27 Jun 2015 14:07:34 +0000 (16:07 +0200)
src/actions.js [new file with mode: 0644]
surfer.js [new file with mode: 0755]

diff --git a/src/actions.js b/src/actions.js
new file mode 100644 (file)
index 0000000..33e47aa
--- /dev/null
@@ -0,0 +1,34 @@
+'use strict';
+
+exports.put = put;
+exports.get = get;
+exports.del = del;
+
+var superagent = require('superagent'),
+    path = require('path');
+
+var server = 'http://localhost:3000/api/files/';
+
+function put(filePath) {
+    var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1);
+    superagent.put(server + relativeFilePath).attach('file', filePath).end(function (error, result) {
+        if (error) return console.log('Failed', result ? result.body : error);
+        console.log('Success', result.body);
+    });
+}
+
+function get(filePath) {
+    var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1);
+    superagent.get(server + relativeFilePath).end(function (error, result) {
+        if (error) return console.log('Failed', result ? result.body : error);
+        console.log('Success', result.body);
+    });
+}
+
+function del(filePath) {
+    var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1);
+    superagent.del(server + relativeFilePath).end(function (error, result) {
+        if (error) return console.log('Failed', result ? result.body : error);
+        console.log('Success', result.body);
+    });
+}
diff --git a/surfer.js b/surfer.js
new file mode 100755 (executable)
index 0000000..703fc59
--- /dev/null
+++ b/surfer.js
@@ -0,0 +1,25 @@
+#!/usr/bin/env node
+
+'use strict';
+
+var program = require('commander'),
+    actions = require('./src/actions');
+
+// Allow self signed certs!
+process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
+
+program.version('0.1.0');
+
+program.command('put')
+    .description('Put a file')
+    .action(actions.put);
+
+program.command('get')
+    .description('Get a file or directory')
+    .action(actions.get);
+
+program.command('del')
+    .description('Delete a file')
+    .action(actions.del);
+
+program.parse(process.argv);