summaryrefslogtreecommitdiff
path: root/tools/eslint/node_modules/js-yaml/node_modules/argparse/examples/sum.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/node_modules/js-yaml/node_modules/argparse/examples/sum.js')
-rwxr-xr-xtools/eslint/node_modules/js-yaml/node_modules/argparse/examples/sum.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/eslint/node_modules/js-yaml/node_modules/argparse/examples/sum.js b/tools/eslint/node_modules/js-yaml/node_modules/argparse/examples/sum.js
new file mode 100755
index 0000000000..4532800a50
--- /dev/null
+++ b/tools/eslint/node_modules/js-yaml/node_modules/argparse/examples/sum.js
@@ -0,0 +1,35 @@
+#!/usr/bin/env node
+
+'use strict';
+
+
+var ArgumentParser = require('../lib/argparse').ArgumentParser;
+var parser = new ArgumentParser({ description: 'Process some integers.' });
+
+
+function sum(arr) {
+ return arr.reduce(function (a, b) {
+ return a + b;
+ }, 0);
+}
+function max(arr) {
+ return Math.max.apply(Math, arr);
+}
+
+
+parser.addArgument(['integers'], {
+ metavar: 'N',
+ type: 'int',
+ nargs: '+',
+ help: 'an integer for the accumulator'
+});
+parser.addArgument(['--sum'], {
+ dest: 'accumulate',
+ action: 'storeConst',
+ constant: sum,
+ defaultValue: max,
+ help: 'sum the integers (default: find the max)'
+});
+
+var args = parser.parseArgs('--sum 1 2 -1'.split(' '));
+console.log(args.accumulate(args.integers));