diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/actions.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/cli/actions.js b/cli/actions.js index 043909d..c8b5c33 100644 --- a/cli/actions.js +++ b/cli/actions.js | |||
@@ -10,6 +10,7 @@ var superagent = require('superagent'), | |||
10 | readlineSync = require('readline-sync'), | 10 | readlineSync = require('readline-sync'), |
11 | async = require('async'), | 11 | async = require('async'), |
12 | fs = require('fs'), | 12 | fs = require('fs'), |
13 | url = require('url'), | ||
13 | path = require('path'); | 14 | path = require('path'); |
14 | 15 | ||
15 | require('colors'); | 16 | require('colors'); |
@@ -48,8 +49,11 @@ function collectFiles(filesOrFolders) { | |||
48 | return tmp; | 49 | return tmp; |
49 | } | 50 | } |
50 | 51 | ||
51 | function login(server) { | 52 | function login(uri) { |
52 | if (server[server.length-1] === '/') server = server.slice(0, -1); | 53 | var tmp = url.parse(uri); |
54 | if (!tmp.host) tmp = url.parse('https://' + uri); | ||
55 | |||
56 | var server = 'https://' + tmp.host; | ||
53 | 57 | ||
54 | console.log('Using server', server); | 58 | console.log('Using server', server); |
55 | 59 | ||
@@ -57,6 +61,10 @@ function login(server) { | |||
57 | var password = readlineSync.question('Password: ', { hideEchoBack: true }); | 61 | var password = readlineSync.question('Password: ', { hideEchoBack: true }); |
58 | 62 | ||
59 | superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) { | 63 | superagent.get(server + API + '/').query({ username: username, password: password }).end(function (error, result) { |
64 | if (error && error.code === 'ENOTFOUND') { | ||
65 | console.log('No such server %s'.red, server); | ||
66 | process.exit(1); | ||
67 | } | ||
60 | if (result.status === 401) { | 68 | if (result.status === 401) { |
61 | console.log('Login failed.'); | 69 | console.log('Login failed.'); |
62 | process.exit(1); | 70 | process.exit(1); |
@@ -70,7 +78,7 @@ function login(server) { | |||
70 | 78 | ||
71 | gQuery = { username: username, password: password }; | 79 | gQuery = { username: username, password: password }; |
72 | 80 | ||
73 | console.log('Done'); | 81 | console.log('Done'.green); |
74 | }); | 82 | }); |
75 | } | 83 | } |
76 | 84 | ||