1 |
|
2 | var colors, pad, stream, string;
|
3 |
|
4 | module.exports = {
|
5 | ssh: null,
|
6 | handler: function(options) {
|
7 | var base, base1, base2, ids, k, ref, v;
|
8 | if (options.log_cli == null) {
|
9 | options.log_cli = {};
|
10 | }
|
11 | ref = options.log_cli;
|
12 | for (k in ref) {
|
13 | v = ref[k];
|
14 | options[k] = v;
|
15 | }
|
16 | if (options.argument != null) {
|
17 | if (options.enabled == null) {
|
18 | options.enabled = options.argument;
|
19 | }
|
20 | }
|
21 | if (options.enabled == null) {
|
22 | options.enabled = true;
|
23 | }
|
24 | if (options.stream == null) {
|
25 | options.stream = process.stdout;
|
26 | }
|
27 | if (options.end == null) {
|
28 | options.end = false;
|
29 | }
|
30 | if (options.divider == null) {
|
31 | options.divider = ' : ';
|
32 | }
|
33 | if (options.depth == null) {
|
34 | options.depth = false;
|
35 | }
|
36 | if (options.pad == null) {
|
37 | options.pad = {};
|
38 | }
|
39 | if (options.time == null) {
|
40 | options.time = true;
|
41 | }
|
42 | if (typeof options.separator === 'string') {
|
43 | options.separator = {
|
44 | host: options.separator,
|
45 | header: options.separator
|
46 | };
|
47 | }
|
48 | if (options.separator == null) {
|
49 | options.separator = {};
|
50 | }
|
51 | if ((base = options.separator).host == null) {
|
52 | base.host = options.pad.host == null ? ' ' : ' ';
|
53 | }
|
54 | if ((base1 = options.separator).header == null) {
|
55 | base1.header = options.pad.header == null ? ' ' : ' ';
|
56 | }
|
57 | if ((base2 = options.separator).time == null) {
|
58 | base2.time = options.pad.time == null ? ' ' : ' ';
|
59 | }
|
60 | if (options.host == null) {
|
61 | options.host = options.ssh ? options.ssh.config.host : 'localhost';
|
62 | }
|
63 | if (options.colors == null) {
|
64 | options.colors = process.stdout.isTTY;
|
65 | }
|
66 | if (options.colors) {
|
67 | options.colors = {
|
68 | host: colors.cyan.dim,
|
69 | header: colors.cyan.dim,
|
70 | status_true: colors.cyan,
|
71 | status_false: colors.cyan,
|
72 | status_error: colors.magenta,
|
73 | time: colors.cyan.dim
|
74 | };
|
75 | }
|
76 | ids = {};
|
77 | return this.call(options, stream, {
|
78 | serializer: {
|
79 | 'diff': null,
|
80 | 'end': function() {
|
81 | return "FINISH\n";
|
82 | },
|
83 | 'error': function(err) {
|
84 | return "ERROR";
|
85 | },
|
86 | 'header': function(log) {
|
87 | if (!options.enabled) {
|
88 | return;
|
89 | }
|
90 | if (options.depth && options.depth < log.headers.length) {
|
91 | return;
|
92 | }
|
93 | ids[log.index] = log;
|
94 | return null;
|
95 | },
|
96 | "handled": function(log) {
|
97 | var header, header_separator, host, host_separator, status, time, time_separator;
|
98 | status = log.error ? 'x' : log.status ? '+' : '-';
|
99 | log = ids[log.index];
|
100 | if (!log) {
|
101 | return null;
|
102 | }
|
103 | delete ids[log.index];
|
104 | time = options.time ? string.print_time(Date.now() - log.time) : '';
|
105 | host = options.host;
|
106 | host_separator = options.separator.host;
|
107 | header = log.headers.join(options.divider);
|
108 | header_separator = options.separator.header;
|
109 | time_separator = options.time ? options.separator.time : '';
|
110 | if (options.pad.host) {
|
111 | host = pad(host, options.pad.host);
|
112 | }
|
113 | if (options.pad.header) {
|
114 | header = pad(header, options.pad.header);
|
115 | }
|
116 | if (options.pad.time) {
|
117 | time = pad(time, options.pad.time);
|
118 | }
|
119 | if (options.colors) {
|
120 | if (options.time) {
|
121 | time = options.colors.time(time);
|
122 | }
|
123 | host = options.colors.host(host);
|
124 | host_separator = options.colors.host(host_separator);
|
125 | header = options.colors.header(header);
|
126 | header_separator = options.colors.host(header_separator);
|
127 | status = log.error ? options.colors.status_error(status) : log.status ? options.colors.status_true(status) : options.colors.status_false(status);
|
128 | }
|
129 | return "" + host + host_separator + header + header_separator + status + time_separator + time + "\n";
|
130 | },
|
131 | 'stdin': null,
|
132 | 'stderr': null,
|
133 | 'stdout': null,
|
134 | 'text': null
|
135 | }
|
136 | });
|
137 | }
|
138 | };
|
139 |
|
140 | colors = require('colors/safe');
|
141 |
|
142 | pad = require('pad');
|
143 |
|
144 | stream = require('./stream');
|
145 |
|
146 | string = require('../misc/string');
|