updated package.json
2
node_modules/cliff/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
19
node_modules/cliff/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2010 Nodejitsu Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
227
node_modules/cliff/README.md
generated
vendored
Normal file
@@ -0,0 +1,227 @@
|
||||
# cliff
|
||||
|
||||
CLI output formatting tools: "Your CLI Formatting Friend".
|
||||
|
||||
## Installation
|
||||
|
||||
### Installing npm (node package manager)
|
||||
```
|
||||
curl http://npmjs.org/install.sh | sh
|
||||
```
|
||||
|
||||
### Installing cliff
|
||||
```
|
||||
[sudo] npm install cliff
|
||||
```
|
||||
|
||||
## Usage
|
||||
There are a number of methods available in Cliff for common logging tasks in command-line tools. If you're looking for more usage, checkout the [examples in this repository][3]:
|
||||
|
||||
1. Logging rows of data
|
||||
2. Inspecting Objects
|
||||
|
||||
### Logging rows of data
|
||||
|
||||
**cliff.stringifyRows(rows[, colors])**
|
||||
|
||||
Takes a set of Arrays and row headers and returns properly formatted and padded rows. Here's a sample:
|
||||
|
||||
``` js
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var rows = [
|
||||
['Name', 'Flavor', 'Dessert'],
|
||||
['Alice', 'cherry', 'yogurt'],
|
||||
['Bob', 'carmel', 'apples'],
|
||||
['Joe', 'chocolate', 'cake'],
|
||||
['Nick', 'vanilla', 'ice cream']
|
||||
];
|
||||
|
||||
console.log(cliff.stringifyRows(rows, ['red', 'blue', 'green']));
|
||||
```
|
||||
|
||||
![output from string-rows.js][string-rows]
|
||||
|
||||
**cliff.putRows(level, rows[, colors])**
|
||||
|
||||
The `putRows` method is a simple helper that takes a set of Arrays and row headers and logs properly formatted and padded rows (logs `stringifyRows` to [winston][0]). Here's a quick sample:
|
||||
|
||||
``` js
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var rows = [
|
||||
['Name', 'Flavor', 'Dessert'],
|
||||
['Alice', 'cherry', 'yogurt'],
|
||||
['Bob', 'carmel', 'apples'],
|
||||
['Joe', 'chocolate', 'cake'],
|
||||
['Nick', 'vanilla', 'ice cream']
|
||||
];
|
||||
|
||||
cliff.putRows('data', rows, ['red', 'blue', 'green']);
|
||||
```
|
||||
|
||||
The resulting output on the command-line would be:
|
||||
|
||||
![output from put-rows.js][put-rows]
|
||||
|
||||
**cliff.stringifyObjectRows(objs, properties[, colors])**
|
||||
*used to be: cliff.rowifyObjects(objs, properties, colors)*
|
||||
|
||||
Takes a set of Objects and the properties to extract from them and returns properly formatted and padded rows. Here's a sample:
|
||||
|
||||
``` js
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var objs = [], obj = {
|
||||
name: "bazz",
|
||||
address: "1234 Nowhere Dr.",
|
||||
};
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
objs.push({
|
||||
name: obj.name,
|
||||
address: obj.address,
|
||||
id: Math.random().toString()
|
||||
});
|
||||
}
|
||||
|
||||
console.log(cliff.stringifyObjectRows(objs, ['id', 'name', 'address'], ['red', 'blue', 'green']));
|
||||
```
|
||||
|
||||
![output from string-object-rows.js][string-object-rows]
|
||||
|
||||
**cliff.putObjectRows(level, objs, properties[, colors])**
|
||||
|
||||
Takes a set of Objects and the properties to extract from them and it will log to the console. (it prints `stringifyObjectRows` with [winston][0]). Here's a sample:
|
||||
|
||||
``` js
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var objs = [], obj = {
|
||||
name: "bazz",
|
||||
address: "1234 Nowhere Dr.",
|
||||
};
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
objs.push({
|
||||
name: obj.name,
|
||||
address: obj.address,
|
||||
id: Math.random().toString()
|
||||
});
|
||||
}
|
||||
|
||||
cliff.putObjectRows('data', objs, ['id', 'name', 'address']);
|
||||
```
|
||||
|
||||
![output from string-object-rows.js][string-object-rows]
|
||||
|
||||
**Colors Parameter**
|
||||
|
||||
The `colors` parameter is an array that colors the first row. It uses the [colors.js][2]. You can use any of those.
|
||||
|
||||
``` js
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var rows = [
|
||||
['Name', 'Flavor', 'Dessert'],
|
||||
['Alice'.grey, 'cherry'.cyan, 'yogurt'.yellow],
|
||||
['Bob'.magenta, 'carmel'.rainbow, 'apples'.white],
|
||||
['Joe'.italic, 'chocolate'.underline, 'cake'.inverse],
|
||||
['Nick'.bold, 'vanilla', 'ice cream']
|
||||
];
|
||||
|
||||
cliff.putRows('data', rows, ['red', 'blue', 'green']);
|
||||
```
|
||||
|
||||
The resulting output on the command-line would be:
|
||||
|
||||
![output from puts-rows-colors.js][put-rows-colors]
|
||||
|
||||
### Inspecting Objects
|
||||
|
||||
**cliff.inspect(obj)**
|
||||
|
||||
The `inspect` method is a lightweight wrapper to a pre-configured [eyes][1] inspector. If you wish to change the coloring of objects that are logged using `cliff` you only need to override `cliff.inspect` with a new [eyes][1] inspector. Here is how to use it:
|
||||
|
||||
``` js
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
console.log(cliff.inspect({
|
||||
literal: "bazz",
|
||||
arr: [
|
||||
"one",
|
||||
2,
|
||||
],
|
||||
obj: {
|
||||
host: "localhost",
|
||||
port: 5984,
|
||||
auth: {
|
||||
username: "admin",
|
||||
password: "password"
|
||||
}
|
||||
}
|
||||
}));
|
||||
```
|
||||
|
||||
![output from inspect.js][inspect]
|
||||
|
||||
**cliff.putObject(obj, [rewriters, padding])**
|
||||
|
||||
The `putObject` method is a simple helper function for prefixing and styling inspected object output from [eyes][1]. Here's a quick sample:
|
||||
|
||||
``` js
|
||||
var cliff = require('cliff');
|
||||
|
||||
cliff.putObject({
|
||||
literal: "bazz",
|
||||
arr: [
|
||||
"one",
|
||||
2,
|
||||
],
|
||||
obj: {
|
||||
host: "localhost",
|
||||
port: 5984,
|
||||
auth: {
|
||||
username: "admin",
|
||||
password: "password"
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The resulting output on the command-line would be:
|
||||
|
||||
![output from put-object.js][put-object]
|
||||
|
||||
## Run Tests
|
||||
|
||||
All of the cliff tests are written in [vows][4], and cover all of the use cases described above.
|
||||
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
## Motivation
|
||||
|
||||
Cliff is the swiss army knife of CLI formatting tools. It is based on highly flexible and powerful libraries:
|
||||
|
||||
* [winston][0]: A multi-transport async logging library for node.js
|
||||
* [eyes][1]: A customizable value inspector for node.js
|
||||
* [colors][2]: Get colors in your node.js console like what
|
||||
|
||||
|
||||
#### Author: [Charlie Robbins](http://twitter.com/indexzero)
|
||||
|
||||
[0]: http://github.com/indexzero/winston
|
||||
[1]: http://github.com/cloudhead/eyes.js
|
||||
[2]: http://github.com/marak/colors.js
|
||||
[3]: http://github.com/flatiron/cliff/tree/master/examples
|
||||
[4]: http://vowsjs.org
|
||||
|
||||
[inspect]: https://github.com/flatiron/cliff/raw/master/assets/inspect.png
|
||||
[put-object-rows]: https://github.com/flatiron/cliff/raw/master/assets/put-object-rows.png
|
||||
[put-object]: https://github.com/flatiron/cliff/raw/master/assets/put-object.png
|
||||
[put-rows-colors]: https://github.com/flatiron/cliff/raw/master/assets/put-rows-colors.png
|
||||
[put-rows]: https://github.com/flatiron/cliff/raw/master/assets/put-rows.png
|
||||
[string-object-rows]: https://github.com/flatiron/cliff/raw/master/assets/string-object-rows.png
|
||||
[string-rows]: https://github.com/flatiron/cliff/raw/master/assets/string-rows.png
|
||||
BIN
node_modules/cliff/assets/inspect.png
generated
vendored
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
node_modules/cliff/assets/put-object-rows.png
generated
vendored
Executable file
|
After Width: | Height: | Size: 54 KiB |
BIN
node_modules/cliff/assets/put-object.png
generated
vendored
Executable file
|
After Width: | Height: | Size: 32 KiB |
BIN
node_modules/cliff/assets/put-rows-colors.png
generated
vendored
Executable file
|
After Width: | Height: | Size: 23 KiB |
BIN
node_modules/cliff/assets/put-rows.png
generated
vendored
Executable file
|
After Width: | Height: | Size: 21 KiB |
BIN
node_modules/cliff/assets/string-object-rows.png
generated
vendored
Executable file
|
After Width: | Height: | Size: 52 KiB |
BIN
node_modules/cliff/assets/string-rows.png
generated
vendored
Executable file
|
After Width: | Height: | Size: 20 KiB |
24
node_modules/cliff/examples/inspect.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* put-object.js: Example usage for `cliff.putObject`.
|
||||
*
|
||||
* (C) 2010, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
console.log(cliff.inspect({
|
||||
literal: "bazz",
|
||||
arr: [
|
||||
"one",
|
||||
2,
|
||||
],
|
||||
obj: {
|
||||
host: "localhost",
|
||||
port: 5984,
|
||||
auth: {
|
||||
username: "admin",
|
||||
password: "password"
|
||||
}
|
||||
}
|
||||
}));
|
||||
23
node_modules/cliff/examples/put-object-rows.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* put-object-rows.js: Example usage for `cliff.putObjectRows`.
|
||||
*
|
||||
* (C) 2010, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var objs = [], obj = {
|
||||
name: "bazz",
|
||||
address: "1234 Nowhere Dr.",
|
||||
};
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
objs.push({
|
||||
name: obj.name,
|
||||
address: obj.address,
|
||||
id: Math.random().toString()
|
||||
});
|
||||
}
|
||||
|
||||
cliff.putObjectRows('data', objs, ['id', 'name', 'address']);
|
||||
24
node_modules/cliff/examples/put-object.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* put-object.js: Example usage for `cliff.putObject`.
|
||||
*
|
||||
* (C) 2010, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
cliff.putObject({
|
||||
literal: "bazz",
|
||||
arr: [
|
||||
"one",
|
||||
2,
|
||||
],
|
||||
obj: {
|
||||
host: "localhost",
|
||||
port: 5984,
|
||||
auth: {
|
||||
username: "admin",
|
||||
password: "password"
|
||||
}
|
||||
}
|
||||
});
|
||||
12
node_modules/cliff/examples/put-rows-colors.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var rows = [
|
||||
['Name', 'Flavor', 'Dessert'],
|
||||
['Alice'.grey, 'cherry'.cyan, 'yogurt'.yellow],
|
||||
['Bob'.magenta, 'carmel'.rainbow, 'apples'.white],
|
||||
['Joe'.italic, 'chocolate'.underline, 'cake'.inverse],
|
||||
['Nick'.bold, 'vanilla', 'ice cream']
|
||||
];
|
||||
|
||||
cliff.putRows('data', rows, ['red', 'blue', 'green']);
|
||||
|
||||
11
node_modules/cliff/examples/put-rows.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var rows = [
|
||||
['Name', 'Flavor', 'Dessert'],
|
||||
['Alice', 'cherry', 'yogurt'],
|
||||
['Bob', 'carmel', 'apples'],
|
||||
['Joe', 'chocolate', 'cake'],
|
||||
['Nick', 'vanilla', 'ice cream']
|
||||
];
|
||||
|
||||
cliff.putRows('data', rows, ['red', 'blue', 'green']);
|
||||
23
node_modules/cliff/examples/string-object-rows.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* put-object-rows.js: Example usage for `cliff.putObjectRows`.
|
||||
*
|
||||
* (C) 2010, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var objs = [], obj = {
|
||||
name: "bazz",
|
||||
address: "1234 Nowhere Dr.",
|
||||
};
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
objs.push({
|
||||
name: obj.name,
|
||||
address: obj.address,
|
||||
id: Math.random().toString()
|
||||
});
|
||||
}
|
||||
|
||||
console.log(cliff.stringifyObjectRows(objs, ['id', 'name', 'address'], ['red', 'blue', 'green']));
|
||||
11
node_modules/cliff/examples/string-rows.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
var cliff = require('../lib/cliff');
|
||||
|
||||
var rows = [
|
||||
['Name', 'Flavor', 'Dessert'],
|
||||
['Alice', 'cherry', 'yogurt'],
|
||||
['Bob', 'carmel', 'apples'],
|
||||
['Joe', 'chocolate', 'cake'],
|
||||
['Nick', 'vanilla', 'ice cream']
|
||||
];
|
||||
|
||||
console.log(cliff.stringifyRows(rows, ['red', 'blue', 'green']));
|
||||
287
node_modules/cliff/lib/cliff.js
generated
vendored
Normal file
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* cliff.js: CLI output formatting tools: "Your CLI Formatting Friend".
|
||||
*
|
||||
* (C) 2010, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var colors = require('colors'),
|
||||
eyes = require('eyes'),
|
||||
winston = require('winston');
|
||||
|
||||
var cliff = exports,
|
||||
logger;
|
||||
|
||||
cliff.__defineGetter__('logger', function () {
|
||||
delete cliff.logger;
|
||||
return cliff.logger = logger;
|
||||
});
|
||||
|
||||
cliff.__defineSetter__('logger', function (val) {
|
||||
logger = val;
|
||||
|
||||
//
|
||||
// Setup winston to use the `cli` formats
|
||||
//
|
||||
if (logger.cli) {
|
||||
logger.cli();
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Set the default logger for cliff.
|
||||
//
|
||||
cliff.logger = new winston.Logger({
|
||||
transports: [new winston.transports.Console()]
|
||||
});
|
||||
|
||||
//
|
||||
// Expose a default `eyes` inspector.
|
||||
//
|
||||
cliff.inspector = eyes.inspector;
|
||||
cliff.inspect = eyes.inspector({ stream: null,
|
||||
styles: { // Styles applied to stdout
|
||||
all: null, // Overall style applied to everything
|
||||
label: 'underline', // Inspection labels, like 'array' in `array: [1, 2, 3]`
|
||||
other: 'inverted', // Objects which don't have a literal representation, such as functions
|
||||
key: 'grey', // The keys in object literals, like 'a' in `{a: 1}`
|
||||
special: 'grey', // null, undefined...
|
||||
number: 'blue', // 0, 1, 2...
|
||||
bool: 'magenta', // true false
|
||||
regexp: 'green' // /\d+/
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
// ### function extractFrom (obj, properties)
|
||||
// #### @obj {Object} Object to extract properties from.
|
||||
// #### @properties {Array} List of properties to output.
|
||||
// Creates an array representing the values for `properties` in `obj`.
|
||||
//
|
||||
cliff.extractFrom = function (obj, properties) {
|
||||
return properties.map(function (p) {
|
||||
return obj[p];
|
||||
});
|
||||
};
|
||||
|
||||
//
|
||||
// ### function columnMajor (rows)
|
||||
// #### @rows {ArrayxArray} Row-major Matrix to transpose
|
||||
// Transposes the row-major Matrix, represented as an array of rows,
|
||||
// into column major form (i.e. an array of columns).
|
||||
//
|
||||
cliff.columnMajor = function (rows) {
|
||||
var columns = [];
|
||||
|
||||
rows.forEach(function (row) {
|
||||
for (var i = 0; i < row.length; i += 1) {
|
||||
if (!columns[i]) {
|
||||
columns[i] = [];
|
||||
}
|
||||
|
||||
columns[i].push(row[i]);
|
||||
}
|
||||
});
|
||||
|
||||
return columns;
|
||||
};
|
||||
|
||||
//
|
||||
// ### arrayLengths (arrs)
|
||||
// #### @arrs {ArrayxArray} Arrays to calculate lengths for
|
||||
// Creates an array with values each representing the length
|
||||
// of an array in the set provided.
|
||||
//
|
||||
cliff.arrayLengths = function (arrs) {
|
||||
var i, lengths = [];
|
||||
for (i = 0; i < arrs.length; i += 1) {
|
||||
lengths.push(longestElement(arrs[i].map(cliff.stringifyLiteral)));
|
||||
}
|
||||
return lengths;
|
||||
};
|
||||
|
||||
//
|
||||
// ### function stringifyRows (rows, colors)
|
||||
// #### @rows {ArrayxArray} Matrix of properties to output in row major form
|
||||
// #### @colors {Array} Set of colors to use for the headers
|
||||
// Outputs the specified `rows` as fixed-width columns, adding
|
||||
// colorized headers if `colors` are supplied.
|
||||
//
|
||||
cliff.stringifyRows = function (rows, colors, options) {
|
||||
var lengths, columns, output = [], headers;
|
||||
|
||||
options = options || {};
|
||||
options.columnSpacing = options.columnSpacing || 2;
|
||||
|
||||
columns = cliff.columnMajor(rows);
|
||||
lengths = cliff.arrayLengths(columns);
|
||||
|
||||
function stringifyRow(row, colorize) {
|
||||
var rowtext = '', padding, item, i, length;
|
||||
for (i = 0; i < row.length; i += 1) {
|
||||
item = cliff.stringifyLiteral(row[i]);
|
||||
|
||||
if(colorize) {
|
||||
item = item[colors[i]] || item[colors[colors.length -1]] || item;
|
||||
}
|
||||
|
||||
length = realLength(item);
|
||||
padding = length < lengths[i] ? lengths[i] - length + options.columnSpacing : options.columnSpacing ;
|
||||
rowtext += item + new Array(padding).join(' ');
|
||||
}
|
||||
|
||||
output.push(rowtext);
|
||||
}
|
||||
|
||||
// If we were passed colors, then assume the first row
|
||||
// is the headers for the rows
|
||||
if (colors) {
|
||||
headers = rows.splice(0, 1)[0];
|
||||
stringifyRow(headers, true);
|
||||
}
|
||||
|
||||
rows.forEach(function (row) {
|
||||
stringifyRow(row, false);
|
||||
});
|
||||
|
||||
return output.join('\n');
|
||||
};
|
||||
|
||||
//
|
||||
// ### function rowifyObjects (objs, properties, colors)
|
||||
// #### @objs {Array} List of objects to create output for
|
||||
// #### @properties {Array} List of properties to output
|
||||
// #### @colors {Array} Set of colors to use for the headers
|
||||
// Extracts the lists of `properties` from the specified `objs`
|
||||
// and formats them according to `cliff.stringifyRows`.
|
||||
//
|
||||
cliff.stringifyObjectRows = cliff.rowifyObjects = function (objs, properties, colors, options) {
|
||||
var rows = [properties].concat(objs.map(function (obj) {
|
||||
return cliff.extractFrom(obj, properties);
|
||||
}));
|
||||
|
||||
return cliff.stringifyRows(rows, colors, options);
|
||||
};
|
||||
|
||||
//
|
||||
// ### function putRows (level, rows, colors)
|
||||
// #### @level {String} Log-level to use
|
||||
// #### @rows {Array} Array of rows to log at the specified level
|
||||
// #### @colors {Array} Set of colors to use for the specified row(s) headers.
|
||||
// Logs the stringified table result from `rows` at the appropriate `level` using
|
||||
// `cliff.logger`. If `colors` are supplied then use those when stringifying `rows`.
|
||||
//
|
||||
cliff.putRows = function (level, rows, colors) {
|
||||
cliff.stringifyRows(rows, colors).split('\n').forEach(function (str) {
|
||||
logger.log(level, str);
|
||||
});
|
||||
};
|
||||
|
||||
//
|
||||
// ### function putObjectRows (level, rows, colors)
|
||||
// #### @level {String} Log-level to use
|
||||
// #### @objs {Array} List of objects to create output for
|
||||
// #### @properties {Array} List of properties to output
|
||||
// #### @colors {Array} Set of colors to use for the headers
|
||||
// Logs the stringified table result from `objs` at the appropriate `level` using
|
||||
// `cliff.logger`. If `colors` are supplied then use those when stringifying `objs`.
|
||||
//
|
||||
cliff.putObjectRows = function (level, objs, properties, colors) {
|
||||
cliff.rowifyObjects(objs, properties, colors).split('\n').forEach(function (str) {
|
||||
logger.log(level, str);
|
||||
});
|
||||
};
|
||||
|
||||
//
|
||||
// ### function putObject (obj, [rewriters, padding])
|
||||
// #### @obj {Object} Object to log to the command line
|
||||
// #### @rewriters {Object} **Optional** Set of methods to rewrite certain object keys
|
||||
// #### @padding {Number} **Optional** Length of padding to put around the output.
|
||||
// Inspects the object `obj` on the command line rewriting any properties which match
|
||||
// keys in `rewriters` if any. Adds additional `padding` if supplied.
|
||||
//
|
||||
cliff.putObject = function (/*obj, [rewriters, padding] */) {
|
||||
var args = Array.prototype.slice.call(arguments),
|
||||
obj = args.shift(),
|
||||
padding = typeof args[args.length - 1] === 'number' && args.pop(),
|
||||
rewriters = typeof args[args.length -1] === 'object' && args.pop(),
|
||||
keys = Object.keys(obj).sort(),
|
||||
sorted = {},
|
||||
matchers = {},
|
||||
inspected;
|
||||
|
||||
padding = padding || 0;
|
||||
rewriters = rewriters || {};
|
||||
|
||||
function pad () {
|
||||
for (var i = 0; i < padding / 2; i++) {
|
||||
logger.data('');
|
||||
}
|
||||
}
|
||||
|
||||
keys.forEach(function (key) {
|
||||
sorted[key] = obj[key];
|
||||
});
|
||||
|
||||
inspected = cliff.inspect(sorted);
|
||||
|
||||
Object.keys(rewriters).forEach(function (key) {
|
||||
matchers[key] = new RegExp(key);
|
||||
});
|
||||
|
||||
pad();
|
||||
inspected.split('\n').forEach(function (line) {
|
||||
Object.keys(rewriters).forEach(function (key) {
|
||||
if (matchers[key].test(line)) {
|
||||
line = rewriters[key](line);
|
||||
}
|
||||
});
|
||||
logger.data(line);
|
||||
});
|
||||
pad();
|
||||
};
|
||||
|
||||
cliff.stringifyLiteral = function stringifyLiteral (literal) {
|
||||
switch (cliff.typeOf(literal)) {
|
||||
case 'number' : return literal + '';
|
||||
case 'null' : return 'null';
|
||||
case 'undefined': return 'undefined';
|
||||
case 'boolean' : return literal + '';
|
||||
default : return literal;
|
||||
}
|
||||
};
|
||||
|
||||
cliff.typeOf = function typeOf(value) {
|
||||
var s = typeof(value),
|
||||
types = [Object, Array, String, RegExp, Number, Function, Boolean, Date];
|
||||
|
||||
if (s === 'object' || s === 'function') {
|
||||
if (value) {
|
||||
types.forEach(function (t) {
|
||||
if (value instanceof t) {
|
||||
s = t.name.toLowerCase();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
s = 'null';
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
};
|
||||
|
||||
function realLength(str) {
|
||||
return ("" + str).replace(/\u001b\[\d+m/g,'').length;
|
||||
}
|
||||
|
||||
function longestElement(a) {
|
||||
var l = 0;
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
var new_l = realLength(a[i]);
|
||||
if (l < new_l) {
|
||||
l = new_l;
|
||||
}
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
89
node_modules/cliff/package.json
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"cliff@0.1.9",
|
||||
"/home/mywebsite/node_modules/broadway"
|
||||
]
|
||||
],
|
||||
"_from": "cliff@0.1.9",
|
||||
"_id": "cliff@0.1.9",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/cliff",
|
||||
"_npmUser": {
|
||||
"email": "jcrugzz@gmail.com",
|
||||
"name": "jcrugzz"
|
||||
},
|
||||
"_npmVersion": "1.4.23",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "cliff",
|
||||
"raw": "cliff@0.1.9",
|
||||
"rawSpec": "0.1.9",
|
||||
"scope": null,
|
||||
"spec": "0.1.9",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/broadway"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/cliff/-/cliff-0.1.9.tgz",
|
||||
"_shasum": "a211e09c6a3de3ba1af27d049d301250d18812bc",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "cliff@0.1.9",
|
||||
"_where": "/home/mywebsite/node_modules/broadway",
|
||||
"author": {
|
||||
"email": "info@nodejitsu.com",
|
||||
"name": "Nodejitsu Inc."
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/flatiron/cliff/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"colors": "0.x.x",
|
||||
"eyes": "0.1.x",
|
||||
"winston": "0.8.x"
|
||||
},
|
||||
"description": "Your CLI formatting friend.",
|
||||
"devDependencies": {
|
||||
"vows": "0.7.x"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "a211e09c6a3de3ba1af27d049d301250d18812bc",
|
||||
"tarball": "http://registry.npmjs.org/cliff/-/cliff-0.1.9.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
},
|
||||
"gitHead": "66462b3de5ddab850675e8e6ac077645d0bfc425",
|
||||
"homepage": "https://github.com/flatiron/cliff",
|
||||
"keywords": [
|
||||
"cli",
|
||||
"logging",
|
||||
"tools",
|
||||
"winston"
|
||||
],
|
||||
"main": "./lib/cliff",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "indexzero",
|
||||
"email": "charlie.robbins@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "jcrugzz",
|
||||
"email": "jcrugzz@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "cliff",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/flatiron/cliff.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vows test/*-test.js --spec"
|
||||
},
|
||||
"version": "0.1.9"
|
||||
}
|
||||
79
node_modules/cliff/test/cliff-test.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* log-test.js: Tests for cliff.
|
||||
*
|
||||
* (C) 2010, Nodejitsu Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
vows = require('vows'),
|
||||
eyes = require('eyes'),
|
||||
cliff = require('../lib/cliff');
|
||||
|
||||
vows.describe('cliff').addBatch({
|
||||
"When using cliff module": {
|
||||
"the columnMajor() method": {
|
||||
"should respond with rows in column major form": function () {
|
||||
var columns, rows = [
|
||||
["1a", "2a", "3a", "4a"],
|
||||
["1b", "2b", "3b", "4b"],
|
||||
["1c", "2c", "3c", "4c"]
|
||||
];
|
||||
|
||||
columns = cliff.columnMajor(rows);
|
||||
for (var i = 0; i < columns.length; i++) {
|
||||
columns[i].forEach(function (val) {
|
||||
assert.isTrue(val.indexOf(i + 1) !== -1);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
"the arrayLengths() method": {
|
||||
"with a set of strings": {
|
||||
"should respond with a list of the longest elements": function () {
|
||||
var lengths, rows = [
|
||||
["1a", "2a", "3a", "4a"],
|
||||
["1b", "2bb", "3b", "4b"],
|
||||
["1c", "2c", "3ccc", "4c"],
|
||||
["1d", "2d", "3dd", "4dddd"]
|
||||
];
|
||||
|
||||
lengths = cliff.arrayLengths(rows);
|
||||
assert.equal(lengths[0], 2);
|
||||
assert.equal(lengths[1], 3);
|
||||
assert.equal(lengths[2], 4);
|
||||
assert.equal(lengths[3], 5);
|
||||
}
|
||||
},
|
||||
"with a set of numbers and strings": {
|
||||
"should respond with a list of the longest elements": function () {
|
||||
var lengths, rows = [
|
||||
[11, "2a", "3a", "4a"],
|
||||
["1b", 222, "3b", "4b"],
|
||||
["1c", "2c", 3333, "4c"],
|
||||
["1d", "2d", "3dd", 44444]
|
||||
];
|
||||
|
||||
lengths = cliff.arrayLengths(rows);
|
||||
assert.equal(lengths[0], 2);
|
||||
assert.equal(lengths[1], 3);
|
||||
assert.equal(lengths[2], 4);
|
||||
assert.equal(lengths[3], 5);
|
||||
}
|
||||
}
|
||||
},
|
||||
"the stringifyRows() method": {
|
||||
"should calculate padding correctly for numbers": function() {
|
||||
var rows = [
|
||||
['a', 'b'],
|
||||
[12345, 1]
|
||||
];
|
||||
|
||||
assert.equal(
|
||||
cliff.stringifyRows(rows),
|
||||
'a b \n12345 1 '
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||