From 59d887dee8dcc39b809e95d20010695ba5fbdd07 Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Sat, 16 Mar 2013 17:46:59 +0100 Subject: [PATCH] Fixes #44 - missing examples in --help. --- History.md | 1 + bin/cleancss | 21 +++++++++++++++++++-- test/binary-test.js | 11 ++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index faefb1c6..595d893f 100644 --- a/History.md +++ b/History.md @@ -3,6 +3,7 @@ * Fixed issue [#46](https://github.com/GoalSmashers/clean-css/issues/46) - preserving special characters in URLs and attributes. +* Fixed issue [#44](https://github.com/GoalSmashers/clean-css/issues/46) - examples in --help. 0.10.1 / 2013-02-14 ================== diff --git a/bin/cleancss b/bin/cleancss index 640ffcad..29fe0832 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -10,6 +10,8 @@ var commands = require('commander'); var packageConfig = fs.readFileSync(path.join(path.dirname(fs.realpathSync(process.argv[1])), '../package.json')); var buildVersion = JSON.parse(packageConfig).version; +var isWindows = process.platform == 'win32'; + // Specify commander options to parse command line params correctly commands .version(buildVersion, '-v, --version') @@ -18,8 +20,23 @@ commands .option('-b, --keep-line-breaks', 'Keep line breaks') .option('--s0', 'Remove all special comments (i.e. /*! special comment */)') .option('--s1', 'Remove all special comments but the first one') - .option('-o, --output [output-file]', 'Use [output-file] as output instead of stdout') - .parse(process.argv); + .option('-o, --output [output-file]', 'Use [output-file] as output instead of stdout'); + +commands.on('--help', function() { + util.puts(' Examples:\n'); + util.puts(' %> cleancss one.css'); + util.puts(' %> cleancss -o one-min.css one.css'); + if (isWindows) { + util.puts(' %> type one.css two.css three.css | cleancss -o merged-and-minified.css'); + } else { + util.puts(' %> cat one.css two.css three.css | cleancss -o merged-and-minified.css'); + util.puts(' %> cat one.css two.css three.css | cleancss | gzip -9 -c > merged-minified-and-gzipped.css.gz'); + } + util.puts(''); + process.exit(); +}); + +commands.parse(process.argv); var options = { source: null, diff --git a/test/binary-test.js b/test/binary-test.js index 276a2389..c3a3ea70 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -36,7 +36,16 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({ 'help': binaryContext('-h', { 'should output help': function(error, stdout) { assert.equal(/Usage:/.test(stdout), true); - } + }, + 'should output one file example': function(error, stdout) { + assert.equal(stdout.indexOf('cleancss -o one-min.css one.css') > -1, true); + }, + 'should output multiple files example': function(error, stdout) { + assert.equal(stdout.indexOf('cat one.css two.css three.css | cleancss -o merged-and-minified.css') > -1, true); + }, + 'should output gzipping multiple files example': function(error, stdout) { + assert.equal(stdout.indexOf('cat one.css two.css three.css | cleancss | gzip -9 -c > merged-minified-and-gzipped.css.gz') > -1, true); + }, }), 'version': binaryContext('-v', { 'should output help': function(error, stdout) { -- 2.34.1