mikeal / node.couchapp.js

Utility for writing couchapps.
Apache License 2.0
406 stars 78 forks source link

Display usage message for unknown commands #72

Closed noprompt closed 5 years ago

noprompt commented 11 years ago

This is the first thing I tried with the binary:

% couchapp --help

/usr/local/lib/node_modules/couchapp/bin.js:10
  if (pathname[0] === '/') return pathname
              ^
TypeError: Cannot read property '0' of undefined
    at abspath (/usr/local/lib/node_modules/couchapp/bin.js:10:15)
    at Object.<anonymous> (/usr/local/lib/node_modules/couchapp/bin.js:78:32)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

I assume others may attempt to do this at some point and be greeted by the same unfriendly error message. This small patch adds a little bit of handling for those situations and keeps things friendly.

Any commands that aren't recognized (ie. couchapp fail) trigger the usage message to be displayed and exit with a 1 status code. help triggers the usage message but exits with a 0 status code. I didn't add the --help or -h flags because I was trying to follow the format.