Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: master
...
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 20 files changed
  • 0 commit comments
  • 1 contributor
View
2  .gitignore
@@ -1,2 +0,0 @@
-node_modules
-npm-debug.log
View
19 LICENSE
@@ -1,19 +0,0 @@
-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.
View
229 README.md
@@ -1,227 +1,4 @@
-# cliff
+# NOTICE: THIS REPOSITORY HAS BEEN MOVED
+## New Project Homepage: [http://github.com/flatiron/cliff](http://github.com/flatiron/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/nodejitsu/cliff/tree/master/examples
-[4]: http://vowsjs.org
-
-[inspect]: https://github.com/nodejitsu/cliff/raw/master/assets/inspect.png
-[put-object-rows]: https://github.com/nodejitsu/cliff/raw/master/assets/put-object-rows.png
-[put-object]: https://github.com/nodejitsu/cliff/raw/master/assets/put-object.png
-[put-rows-colors]: https://github.com/nodejitsu/cliff/raw/master/assets/put-rows-colors.png
-[put-rows]: https://github.com/nodejitsu/cliff/raw/master/assets/put-rows.png
-[string-object-rows]: https://github.com/nodejitsu/cliff/raw/master/assets/string-object-rows.png
-[string-rows]: https://github.com/nodejitsu/cliff/raw/master/assets/string-rows.png
+<img src="http://c713548.r48.cf2.rackcdn.com/flatiron-github.png" />
View
BIN  assets/inspect.png
Deleted file not rendered
View
BIN  assets/put-object-rows.png
Deleted file not rendered
View
BIN  assets/put-object.png
Deleted file not rendered
View
BIN  assets/put-rows-colors.png
Deleted file not rendered
View
BIN  assets/put-rows.png
Deleted file not rendered
View
BIN  assets/string-object-rows.png
Deleted file not rendered
View
BIN  assets/string-rows.png
Deleted file not rendered
View
24 examples/inspect.js
@@ -1,24 +0,0 @@
-/*
- * 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"
- }
- }
-}));
View
23 examples/put-object-rows.js
@@ -1,23 +0,0 @@
-/*
- * 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']);
View
24 examples/put-object.js
@@ -1,24 +0,0 @@
-/*
- * 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"
- }
- }
-});
View
12 examples/put-rows-colors.js
@@ -1,12 +0,0 @@
-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']);
-
View
11 examples/put-rows.js
@@ -1,11 +0,0 @@
-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']);
View
23 examples/string-object-rows.js
@@ -1,23 +0,0 @@
-/*
- * 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']));
View
11 examples/string-rows.js
@@ -1,11 +0,0 @@
-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']));
View
277 lib/cliff.js
@@ -1,277 +0,0 @@
-/*
- * 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 () {
- return 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();
-
-//
-// 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) {
- var lengths, columns, output = [], headers;
-
- 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]);
- item = colorize ? item[colors[i]] : item;
- length = realLength(item);
- padding = length < lengths[i] ? lengths[i] - length + 2 : 2;
- 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) {
- var rows = [properties].concat(objs.map(function (obj) {
- return cliff.extractFrom(obj, properties);
- }));
-
- return cliff.stringifyRows(rows, colors);
-};
-
-//
-// ### 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;
-}
View
22 package.json
@@ -1,22 +0,0 @@
-{
- "name": "cliff",
- "description": "Your CLI formatting friend.",
- "version": "0.1.7",
- "author": "Nodejitsu <info@nodejitsu.com>",
- "repository": {
- "type": "git",
- "url": "http://github.com/nodejitsu/cliff.git"
- },
- "keywords": ["cli", "logging", "tools", "winston"],
- "dependencies": {
- "colors": "0.x.x",
- "eyes": "0.1.x",
- "winston": "0.5.x"
- },
- "devDependencies": {
- "vows": "0.5.x"
- },
- "main": "./lib/cliff",
- "scripts": { "test": "vows test/*-test.js --spec" },
- "engines": { "node": ">= 0.4.0" }
-}
View
79 test/cliff-test.js
@@ -1,79 +0,0 @@
-/*
- * 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);

No commit comments for this range

Something went wrong with that request. Please try again.