Permalink
Browse files

Make arg parsing more sane

  • Loading branch information...
1 parent cd28202 commit a05348f67f57b1b743f7dd285e8af95f312a45fd @gjtorikian committed Aug 24, 2012
Showing with 99 additions and 80 deletions.
  1. +1 −1 README.md
  2. +6 −75 bin/panda-docs
  3. +6 −2 build.js
  4. +80 −0 lib/cli.js
  5. +4 −0 lib/version.js
  6. +2 −2 package.json
View
@@ -203,6 +203,6 @@ where
Thus, to generate the above, your Jade template might go:
-```jade
+```
!= headingTable(toh, 5, ['tocContainer', 'tocItem'])
```
View
@@ -16,86 +16,16 @@ var panda = require('../index.js'),
var async = require('async');
var helpers = require('../lib/helpers');
+var cli = require('../lib/cli');
+
var panda_docs = exports;
var manifestFile;
-panda_docs.make = exports.make = function(args, callback) {
- var options = nomnom
- .option('manifestPath', {
- position: 0,
- list: false,
- required: true,
- help: 'The location of the manifest file',
- metavar: 'String'
- })
- .option('output', {
- abbr: 'o',
- list: false,
- required: false,
- help: 'Resulting file(s) location [out]',
- metavar: 'String',
- default: 'out'
- })
- .option('outputAssets', {
- list: false,
- required: false,
- full: 'outputAssets',
- help: 'Resulting file(s) location for assets [out/assets]',
- metavar: 'String',
- default: 'out/assets'
- })
- .option('help', {
- abbr: 'h',
- full: 'help',
- help: 'Displays this help information',
- default: false
- })
- .option('title', {
- abbr: 't',
- full: 'title',
- help: 'Title of the index page [Panda: Default Title Here]',
- metavar: 'String',
- default: 'Panda: Default Title Here'
- })
- .option('template', {
- full: 'template',
- help: 'The location of your Jade templates',
- metavar: 'String',
- default: './templates/default/layout.jade'
- })
- .option('assets', {
- full: 'assets',
- help: 'The location of your asset files (CSS, Javascript, e.t.c.)',
- metavar: 'String',
- default: './templates/default/assets'
- })
- .option('disableTests', {
- abbr: 'd',
- full: 'disableTests',
- help: 'Disables the tests that are run at the end of a build. This is NOT recommended.',
- flag: true
- })
- .option('noRelease', {
- abbr: 'r',
- full: 'no-release',
- help: 'If set, indicates that you\'re not doing a release',
- flag: true
- })
- .option('keepFirstHeader', {
- full: 'keepFirstHeader',
- help: 'If set, keeps the first header (<h1>) detected',
- flag: true
- })
- .option('baseUrl', {
- full: 'baseurl',
- help: 'Base url of all links [./]',
- metavar: 'String',
- default: './'
- })
- .parse(args);
+
+panda_docs.make = exports.make = function(manifestFile, args, callback) {
+ var options = cli.parseArgs();
destDir = options.output;
- manifestFile = options.manifestPath || args[0];
manifests = [];
@@ -105,6 +35,7 @@ panda_docs.make = exports.make = function(args, callback) {
cbReturn = {};
cbReturn.files = [ ];
+ console.log(options)
async.series([
function(cb) {
if (manifestFile !== undefined && fs.statSync(manifestFile)) {
View
@@ -1,7 +1,11 @@
var panda = require("./bin/panda-docs");
-panda.make(["./src/manifest.json", "-t", "Panda (from script)"], function(err) {
- if (err !== undefined) {
+var options = {
+ title: "Panda (from script)"
+}
+
+panda.make("./src/manifest.json", options, function(err) {
+ if (err) {
console.error(err);
}
});
View
@@ -0,0 +1,80 @@
+var argparse = require('argparse');
+var ArgumentParser = argparse.ArgumentParser;
+
+var cli = module.exports = new ArgumentParser({
+ version: require('./version'),
+ addHelp: true,
+ formatterClass: function(options) {
+ options['maxHelpPosition'] = 40;
+ return new argparse.HelpFormatter(options);
+ }
+});
+
+cli.addArgument(['--manifest'], {
+ help: 'The location of the manifest file',
+ dest: 'output',
+ metavar: 'PATH'
+});
+
+cli.addArgument(['-o', '--output'], {
+ help: 'Resulting file(s) location [out]',
+ dest: 'output',
+ metavar: 'PATH',
+ defaultValue: 'out'
+});
+
+cli.addArgument(['-oa', '--outputAssets'], {
+ help: 'Resulting file(s) location for assets [out/assets]',
+ dest: 'outputAssets',
+ metavar: 'PATH',
+ defaultValue: 'out/assets'
+});
+
+cli.addArgument(['-t', '--title'], {
+ help: 'Title of the index page [Panda: Default Title Here]',
+ dest: 'title',
+ metavar: 'STRING',
+ defaultValue: 'Panda: Default Title Here'
+});
+
+cli.addArgument(['--template'], {
+ help: 'The location of your primary Jade template [./templates/default/layout.jade]',
+ dest: 'template',
+ metavar: 'PATH',
+ defaultValue: './templates/default/layout.jade'
+});
+
+cli.addArgument(['--assets'], {
+ help: 'The location of your asset files (CSS, Javascript, e.t.c.) [./templates/default/assets]',
+ dest: 'assets',
+ metavar: 'PATH',
+ defaultValue: './templates/default/assets'
+});
+
+cli.addArgument(['-d', '--disableTests'], {
+ help: 'Disables the test suite that runs at the end of an HTML build. This is NOT recommended.',
+ dest: 'disableTests',
+ action: 'storeTrue',
+ defaultValue: false
+});
+
+cli.addArgument(['-nr', '--noRelease'], {
+ help: 'If set, indicates that you\'re not doing a release',
+ dest: 'noRelease',
+ action: 'storeTrue',
+ defaultValue: false
+});
+
+cli.addArgument(['--keepFirstHeader'], {
+ help: 'If set, keeps the first header (<h1>) detected',
+ dest: 'keepFirstHeader',
+ action: 'storeTrue',
+ defaultValue: false
+});
+
+cli.addArgument(['--baseUrl'], {
+ help: 'Base url of all links [./]',
+ dest: 'baseUrl',
+ metavar: 'STRING',
+ defaultValue: './'
+});
View
@@ -0,0 +1,4 @@
+'use strict';
+
+// Shortcut to current Panino's version from the package.json
+module.exports = require('../package.json').version;
View
@@ -1,6 +1,6 @@
{
"name": "panda-docs",
- "version": "0.3.14",
+ "version": "0.3.15",
"author": "Garen Torikian",
"keywords": ["documentation", "docs", "markdown"],
"description": "A complete documentation generation tool for Markdown files",
@@ -19,7 +19,7 @@
"async": ">=0.1.18",
"wrench": ">=1.3.8",
"jade": ">=0.26.1",
- "nomnom": ">=1.5.1",
+ "argparse" : ">=0.1.3",
"markdown_conrefs": ">=1.2.3",
"findit": ">=0.1.2",
"functional-docs": ">=0.0.3"

0 comments on commit a05348f

Please sign in to comment.