]> git.immae.eu Git - perso/Immae/Projets/Nodejs/Surfer.git/blobdiff - cli/actions.js
Add ldap auth
[perso/Immae/Projets/Nodejs/Surfer.git] / cli / actions.js
index 592d8090193f39e2ca4f66b0afba341ded2f4b7e..b35b8dad4ee1f4bea83aafa1c3ced644398ca0ad 100644 (file)
@@ -20,6 +20,8 @@ function checkConfig() {
         console.log('You have run "login" first');
         process.exit(1);
     }
+
+    console.log('Using server %s', config.server().yellow);
 }
 
 function collectFiles(filesOrFolders) {
@@ -42,11 +44,13 @@ function collectFiles(filesOrFolders) {
 }
 
 function login(server) {
+    if (server[server.length-1] === '/') server = server.slice(0, -1);
+
     console.log('Using server', server);
     config.set('server', server);
 }
 
-function put(filePath, otherFilePaths) {
+function put(filePath, otherFilePaths, options) {
     checkConfig();
 
     var files = collectFiles([ filePath ].concat(otherFilePaths));
@@ -54,7 +58,7 @@ function put(filePath, otherFilePaths) {
     async.eachSeries(files, function (file, callback) {
         var relativeFilePath = path.resolve(file).slice(process.cwd().length + 1);
 
-        console.log('Uploading file %s', relativeFilePath.cyan);
+        console.log('Uploading file %s -> %s', relativeFilePath.cyan, ((options.destination ? options.destination : '') + '/' + relativeFilePath).cyan);
 
         superagent.put(config.server() + API + relativeFilePath).attach('file', file).end(callback);
     }, function (error) {
@@ -90,6 +94,7 @@ function del(filePath) {
 
     var relativeFilePath = path.resolve(filePath).slice(process.cwd().length + 1);
     superagent.del(config.server() + API + relativeFilePath).end(function (error, result) {
+        if (error.status === 404) return console.log('No such file or directory');
         if (error) return console.log('Failed', result ? result.body : error);
         console.log('Success', result.body);
     });