One Hat Cyber Team
Your IP :
10.30.1.1
Server IP :
103.148.201.5
Server :
Linux web-olt 5.15.0-161-generic #171-Ubuntu SMP Sat Oct 11 08:17:01 UTC 2025 x86_64
Server Software :
Apache/2.4.52 (Ubuntu)
PHP Version :
8.1.29
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
doc
/
node-commander
/
examples
/
View File Name :
options-custom-processing.js
#!/usr/bin/env node // This is used as an example in the README for: // Custom option processing // You may specify a function to do custom processing of option values. // const commander = require('commander'); // (normal include) const commander = require('../'); // include commander in git clone of commander repo const program = new commander.Command(); function myParseInt(value, dummyPrevious) { // parseInt takes a string and a radix const parsedValue = parseInt(value, 10); if (isNaN(parsedValue)) { throw new commander.InvalidArgumentError('Not a number.'); } return parsedValue; } function increaseVerbosity(dummyValue, previous) { return previous + 1; } function collect(value, previous) { return previous.concat([value]); } function commaSeparatedList(value, dummyPrevious) { return value.split(','); } program .option('-f, --float <number>', 'float argument', parseFloat) .option('-i, --integer <number>', 'integer argument', myParseInt) .option('-v, --verbose', 'verbosity that can be increased', increaseVerbosity, 0) .option('-c, --collect <value>', 'repeatable value', collect, []) .option('-l, --list <items>', 'comma separated list', commaSeparatedList) ; program.parse(); const options = program.opts(); if (options.float !== undefined) console.log(`float: ${options.float}`); if (options.integer !== undefined) console.log(`integer: ${options.integer}`); if (options.verbose > 0) console.log(`verbosity: ${options.verbose}`); if (options.collect.length > 0) console.log(options.collect); if (options.list !== undefined) console.log(options.list); // Try the following: // node options-custom-processing -f 1e2 // node options-custom-processing --integer 2 // node options-custom-processing -v -v -v // node options-custom-processing -c a -c b -c c // node options-custom-processing --list x,y,z