mecano
Version:
Common functions for system deployment.
147 lines (141 loc) • 4.34 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var colors, pad, stream, string;
module.exports = {
ssh: null,
handler: function(options) {
var base, base1, base2, ids, k, ref, v;
if (options.log_cli == null) {
options.log_cli = {};
}
ref = options.log_cli;
for (k in ref) {
v = ref[k];
options[k] = v;
}
if (options.argument != null) {
if (options.enabled == null) {
options.enabled = options.argument;
}
}
if (options.enabled == null) {
options.enabled = true;
}
if (options.stream == null) {
options.stream = process.stdout;
}
if (options.end == null) {
options.end = false;
}
if (options.divider == null) {
options.divider = ' : ';
}
if (options.depth == null) {
options.depth = false;
}
if (options.pad == null) {
options.pad = {};
}
if (options.time == null) {
options.time = true;
}
if (typeof options.separator === 'string') {
options.separator = {
host: options.separator,
header: options.separator
};
}
if (options.separator == null) {
options.separator = {};
}
if ((base = options.separator).host == null) {
base.host = options.pad.host == null ? ' ' : ' ';
}
if ((base1 = options.separator).header == null) {
base1.header = options.pad.header == null ? ' ' : ' ';
}
if ((base2 = options.separator).time == null) {
base2.time = options.pad.time == null ? ' ' : ' ';
}
if (options.host == null) {
options.host = options.ssh ? options.ssh.config.host : 'localhost';
}
if (options.colors == null) {
options.colors = process.stdout.isTTY;
}
if (options.colors) {
options.colors = {
host: colors.cyan.dim,
header: colors.cyan.dim,
status_true: colors.cyan,
status_false: colors.cyan,
status_error: colors.magenta,
time: colors.cyan.dim
};
}
ids = {};
return this.call(options, stream, {
serializer: {
'diff': null,
'end': function() {
return "FINISH\n";
},
'error': function(err) {
return "ERROR";
},
'header': function(log) {
if (!options.enabled) {
return;
}
if (options.depth && options.depth < log.headers.length) {
return;
}
ids[log.index] = log;
return null;
},
"handled": function(log) {
var header, header_separator, host, host_separator, status, time, time_separator;
status = log.error ? 'x' : log.status ? '+' : '-';
log = ids[log.index];
if (!log) {
return null;
}
delete ids[log.index];
time = options.time ? string.print_time(Date.now() - log.time) : '';
host = options.host;
host_separator = options.separator.host;
header = log.headers.join(options.divider);
header_separator = options.separator.header;
time_separator = options.time ? options.separator.time : '';
if (options.pad.host) {
host = pad(host, options.pad.host);
}
if (options.pad.header) {
header = pad(header, options.pad.header);
}
if (options.pad.time) {
time = pad(time, options.pad.time);
}
if (options.colors) {
if (options.time) {
time = options.colors.time(time);
}
host = options.colors.host(host);
host_separator = options.colors.host(host_separator);
header = options.colors.header(header);
header_separator = options.colors.host(header_separator);
status = log.error ? options.colors.status_error(status) : log.status ? options.colors.status_true(status) : options.colors.status_false(status);
}
return "" + host + host_separator + header + header_separator + status + time_separator + time + "\n";
},
'stdin': null,
'stderr': null,
'stdout': null,
'text': null
}
});
}
};
colors = require('colors/safe');
pad = require('pad');
stream = require('./stream');
string = require('../misc/string');