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')
.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,
'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) {