OSDN Git Service

Regular updates
[twpd/master.git] / nopt.md
diff --git a/nopt.md b/nopt.md
new file mode 100644 (file)
index 0000000..0da5afd
--- /dev/null
+++ b/nopt.md
@@ -0,0 +1,50 @@
+---
+title: Nopt
+category: JavaScript libraries
+---
+
+```js
+var args = require('nopt')({
+  foo: [String, null],
+  size: ['big', 'medium', 'small'],
+  many: [String, Array],
+  debug: Boolean,
+  version: Boolean,
+  help: Boolean
+}, {
+  h: '--help',
+  v: '--version'
+}, process.argv);
+
+args == {
+  debug: true,
+  version: true,
+  size: 'big',
+  argv: {
+    remain: ['...', '...'],
+    cooked: ...,
+    original: ...
+  }
+}
+```
+
+```js
+if (args.help) {
+  console.log([
+      'Usage:',
+      '  hicat [options] [file]',
+      '',
+      'Options:',
+      '  -h, --help         print usage information',
+      '  -v, --version      show version info and exit',
+  ].join('\n'));
+  process.exit(0);
+}
+
+if (args.version) {
+  console.log(require('../package.json').version);
+  process.exit(0);
+}
+```
+
+https://www.npmjs.org/package/nopt