-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
I have a very simple demo
at first ,show my code
my index.js
#!/usr/bin/env node
const program = require('commander');
console.log("process.argv==>",process.argv)
console.log("process.argv.splice(2)==>",process.argv.splice(2))
//var arguments = process.argv.splice(2)
program
.version('0.0.1')
.usage('[options]')
.option('-n, --name <name>', 'Your name.')
.parse(process.argv);
// program.args < 0 noting input
if (program.args.length < 1) {
program.outputHelp(); // show help
process.exit(); // exit
}
console.log('Hello, %s.', (program.name || 'World'));package.json
{
"name": "s9cli",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"s9cli": "./index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"commander": "^2.19.0"
}
}
soon ,i exec sudo npm link
next i run s9cli -n sss
result is:
daiyc@ubuntu-cd-69:~/myPrj/s9cli$ s9cli -n sss
process.argv==>[ '/usr/local/bin/node', '/usr/local/bin/s9cli', '-n', 'sss' ]
process.argv.splice(2)==>[ '-n', 'sss' ]
Usage: s9cli [options]
Options:
-V, --version output the version number
-n, --name <name> Your name.
-h, --help output usage information
daiyc@ubuntu-cd-69:~/myPrj/s9cli$
node version: v8.5.0
Linux version: 3.19.0-42-generic (buildd@lgw01-24) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #48~14.04.1-Ubuntu SMP Fri Dec 18 10:24:49 UTC 2015
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels