From de40fd4e425425494c4556a9af83c64a7361d11e Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Mon, 21 Jan 2013 16:11:38 +0100 Subject: [PATCH] added dpi parameter to carto bin use optimist to parse command line arguments --- bin/carto | 56 +++++++++++++++++++++------------------------------- package.json | 7 ++++--- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/bin/carto b/bin/carto index 1ef7cd8..91c672d 100755 --- a/bin/carto +++ b/bin/carto @@ -8,47 +8,33 @@ var path = require('path'), var existsSync = require('fs').existsSync || require('path').existsSync -var args = process.argv.slice(1); -var options = { nosymlink:false }; +var optimist = require('optimist') + .usage("Usage: $0 ") + .options('h', {alias:'help', describe:'Display this help message'}) + .options('v', {alias:'version', boolean:true, describe:'Display version information'}) + .options('b', {alias:'benchmark', boolean:true, describe:'Outputs total compile time'}) + .options('n', {alias:'nosymlink', boolean:true, describe:'Use absolute paths instead of symlinking files'}) + .options('dpi', {describe:'Dpi used to convert m, mm, cm, pt, pc to pixels', default:90.714}); -args = args.filter(function (arg) { - var match; +var options = optimist.argv; - if (match = arg.match(/^--?([a-z][0-9a-z-]*)$/i)) { arg = match[1] } - else { return arg } +if (options.help) { + optimist.showHelp(); + process.exit(0); +} - switch (arg) { - case 'v': - case 'version': - console.log("carto " + carto.version.join('.') + " (Carto map stylesheet compiler)"); - process.exit(0); - break; - case 'b': - case 'benchmark': - options.benchmark = true; - break; - case 'n': - case 'nosymlink': - options.nosymlink = true; - break; - default: - console.log("Usage: carto "); - console.log("Options:"); - console.log(" -v --version Parse JSON map manifest"); - console.log(" -b --benchmark Outputs total compile time"); - console.log(" -n --nosymlink Use absolute paths instead of symlinking files"); - process.exit(0); - break; - } -}); +if (options.version) { + console.log("carto " + carto.version.join('.') + " (Carto map stylesheet compiler)"); + process.exit(0); +} -var input = args[1]; +var input = options._[0]; if (input && input[0] != '/') { input = path.join(process.cwd(), input); } if (!input) { - console.log("carto: no input files"); + console.log("carto: no input files ('carto --help' for help)"); process.exit(1); } @@ -76,7 +62,8 @@ function compileMML(err, data) { try { var renderer = new carto.Renderer({ filename: input, - benchmark: options.benchmark + benchmark: options.benchmark, + dpi: options.dpi }); renderer.render(data, function(err, output) { if (err) { @@ -110,7 +97,8 @@ function compileMSS(err, data) { try { var renderer = new carto.Renderer({ filename: path.basename(input), - benchmark: options.benchmark + benchmark: options.benchmark, + dpi:options.dpi }); renderer.renderMSS(data, function(err, output) { if (err) { diff --git a/package.json b/package.json index b5fc3ff..5b63d71 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "Mapnik Stylesheet Compiler", "url": "https://github.com/mapbox/carto", "repositories": [{ - "type": "git", - "url": "http://github.com/mapbox/carto.git" + "type": "git", + "url": "http://github.com/mapbox/carto.git" }], "author": { "name": "MapBox", @@ -37,7 +37,8 @@ "dependencies": { "underscore": "~1.4.3", "mapnik-reference": "~5.0.3", - "xml2js": "~0.1.13" + "xml2js": "~0.1.13", + "optimist": "~0.3.5" }, "devDependencies": { "mocha": "1.7.x",