Skip to content
Browse files

GH-10 sdc-setup fails on node 0.6.x

  • Loading branch information...
1 parent 0a98a1f commit 13468a1a917163e2990bd076e086ddb605a05e9c Mark Cavage committed Dec 5, 2011
Showing with 58 additions and 68 deletions.
  1. +58 −68 bin/sdc-setup
View
126 bin/sdc-setup
@@ -4,6 +4,7 @@
var fs = require('fs');
var path = require('path');
+var tty = require('tty');
var URL = require('url');
var nopt = require('nopt');
@@ -30,7 +31,6 @@ var ShortOptions = {
var buffer = '';
var log = restify.log;
-var stdio = process.binding('stdio');
var usageStr = common.buildUsageString(Options);
usageStr += ' url';
@@ -40,78 +40,67 @@ usageStr += ' url';
// Totally ripped off from npm. Thanks isaacs@!
-function read(def, cb) {
- var stdin = process.openStdin();
- var val = '';
- stdin.resume();
- stdin.setEncoding('utf8');
- stdin.on('error', cb)
- stdin.on('data', function D (chunk) {
- val += buffer + chunk;
- buffer = '';
- val = val.replace(/\r/g, '');
- if (val.indexOf('\n') !== -1) {
- if (val !== '\n')
- val = val.replace(/^\n+/, '');
- buffer = val.substr(val.indexOf('\n'));
- val = val.substr(0, val.indexOf('\n'));
- stdin.pause();
- stdin.removeListener('data', D);
- stdin.removeListener('error', cb);
- val = val.trim() || def;
- cb(null, val);
- }
- });
+function prompt (p, def, silent, cb) {
+ if (!cb) cb = silent, silent = false
+ if (!cb) cb = def, def = null
+ if (def) p += "("+(silent ? "<hidden>" : def)+") "
+ var r = (silent ? silentRead : read).bind(null, def, cb)
+ if (!process.stdout.write(p)) process.stdout.on("drain", function D () {
+ process.stdout.removeListener("drain", D)
+ r()
+ })
+ else r()
}
-
-function silentRead(def, cb) {
- var stdin = process.openStdin();
- var val = '';
- stdio.setRawMode(true);
- stdin.resume();
- stdin.on('error', cb)
- stdin.on('data', function D (c) {
- c = '' + c
- switch (c) {
- case '\n':
- case '\r':
- case '\r\n':
- case '\u0004':
- stdio.setRawMode(false);
- stdin.removeListener('data', D);
- stdin.removeListener('error', cb);
- val = val.trim() || def;
- process.stdout.write('\n');
- process.stdout.flush();
- stdin.pause();
- return cb(null, val);
- case '\u0003':
- case '\0':
- return cb('cancelled');
- break;
- default:
- val += buffer + c;
- buffer = '';
- break;
+function read (def, cb) {
+ var stdin = process.openStdin()
+ , val = ""
+ stdin.resume()
+ stdin.setEncoding("utf8")
+ stdin.on("error", cb)
+ stdin.on("data", function D (chunk) {
+ val += buffer + chunk
+ buffer = ""
+ val = val.replace(/\r/g, '')
+ if (val.indexOf("\n") !== -1) {
+ if (val !== "\n") val = val.replace(/^\n+/, "")
+ buffer = val.substr(val.indexOf("\n"))
+ val = val.substr(0, val.indexOf("\n"))
+ stdin.pause()
+ stdin.removeListener("data", D)
+ stdin.removeListener("error", cb)
+ val = val.trim() || def
+ cb(null, val)
}
- });
+ })
}
-
-function prompt(p, def, silent, cb) {
- if (!cb) cb = silent, silent = false;
- if (!cb) cb = def, def = undefined;
- if (def) p += '('+ (silent ? '<hidden>' : def)+') ';
- var r = (silent ? silentRead : read).bind(null, def, cb);
- if (!process.stdout.write(p)) {
- process.stdout.on('drain', function D () {
- process.stdout.removeListener('drain', D);
- r()
- });
- } else {
- r();
- }
+function silentRead (def, cb) {
+ var stdin = process.openStdin()
+ , val = ""
+ tty.setRawMode(true)
+ stdin.resume()
+ stdin.on("error", cb)
+ stdin.on("data", function D (c) {
+ c = "" + c
+ switch (c) {
+ case "\n": case "\r": case "\r\n": case "\u0004":
+ tty.setRawMode(false)
+ stdin.removeListener("data", D)
+ stdin.removeListener("error", cb)
+ val = val.trim() || def
+ process.stdout.write("\n")
+ stdin.pause()
+ return cb(null, val)
+ case "\u0003": case "\0":
+ return cb("cancelled")
+ break
+ default:
+ val += buffer + c
+ buffer = ""
+ break
+ }
+ })
}
@@ -157,6 +146,7 @@ function uploadKey(client, url, account) {
dumpEnvVars(url, account, key.name);
console.log('export SDC_CLI_IDENTITY=' + file.replace(/\.pub$/, ''));
+ process.exit(0);
});
});
}

0 comments on commit 13468a1

Please sign in to comment.
Something went wrong with that request. Please try again.