Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

awesome npm-style ps list

  • Loading branch information...
commit f99be7b900270938dd38d9324bb6a54e9808818e 1 parent 9d42dcb
@substack authored
Showing with 63 additions and 32 deletions.
  1. +0 −32 bin/list.js
  2. +63 −0 bin/ps.js
View
32 bin/list.js
@@ -1,32 +0,0 @@
-#!/usr/bin/env node
-var argv = require('../lib/argv');
-var propagit = require('propagit');
-var seaport = require('seaport');
-var EventEmitter = require('events').EventEmitter;
-
-var p = propagit(argv);
-p.on('error', function (err) {
- console.dir(err);
-});
-
-p.hub.on('up', function (hub) {
- var em = new EventEmitter;
- console.log('{');
- var ix = 0;
-
- em.on('data', function (key, procs) {
- if (ix++ > 0) process.stdout.write(',\n');
-
- process.stdout.write(
- ' ' + JSON.stringify(key) + ' : '
- + JSON.stringify(procs).replace(/\n/g, '\n ')
- );
- });
-
- em.on('end', function () {
- console.log('\n}');
- p.hub.close();
- });
-
- hub.ps(em.emit.bind(em));
-});
View
63 bin/ps.js
@@ -0,0 +1,63 @@
+#!/usr/bin/env node
+var argv = require('../lib/argv');
+var propagit = require('propagit');
+var EventEmitter = require('events').EventEmitter;
+
+var p = propagit(argv);
+p.on('error', function (err) {
+ console.dir(err);
+});
+
+p.hub.on('up', argv.json ? raw : text);
+
+function text (hub) {
+ var em = new EventEmitter;
+
+ em.on('data', function (key, procs) {
+ console.log('drone#' + key);
+
+ var pids = Object.keys(procs);
+ pids.forEach(function (pid, ix) {
+ var last = ix === pids.length - 1;
+ var p = procs[pid];
+ console.log(
+ (last ? '' : '') + '─┬ '
+ + 'pid#' + pid
+ );
+ console.log([
+ '',
+ ' ├── status: ' + p.status,
+ ' ├── commit: ' + p.repo + '/' + p.commit,
+ ' └── command: ' + p.command.join(' '),
+ ].join('\n' + (last ? ' ' : '')).slice(1));
+ });
+ });
+
+ em.on('end', function () {
+ p.hub.close();
+ });
+
+ hub.ps(em.emit.bind(em));
+}
+
+function raw (hub) {
+ var em = new EventEmitter;
+ console.log('{');
+ var ix = 0;
+
+ em.on('data', function (key, procs) {
+ if (ix++ > 0) process.stdout.write(',\n');
+
+ process.stdout.write(
+ ' ' + JSON.stringify(key) + ' : '
+ + JSON.stringify(procs).replace(/\n/g, '\n ')
+ );
+ });
+
+ em.on('end', function () {
+ console.log('\n}');
+ p.hub.close();
+ });
+
+ hub.ps(em.emit.bind(em));
+}
Please sign in to comment.
Something went wrong with that request. Please try again.