argv-one
v1.0.1
Published
cross-platform helper for `process.argv[1]`
Downloads
3
Maintainers
Readme
argv-one
cross-platform helper for process.argv[1]
Why?
I've recently started writing CLI tools for Windows with Node.js,
and I've noticed that process.argv[1]
doesn't have the same value there.
Installation
npm install --save argv-one
Usage
- package.json:
{
"bin": {
"my-cli": "bin/index.js"
}
}
- bin/index.js:
#!/usr/bin/env node
var cmd = require('argv-one')({ argv: process.argv });
console.log(process.argv[1]);
// Windows: => "C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules\\my-cli\\bin\\index.js"
// OS X or Linux: => "my-cli"
console.log(cmd);
// Windows, OSX or Linux: => "my-cli"
API
argvOne({ argv?: String[], pkg?: Object, pkgPath?: String }) => String
If there is nothing wrong with your CLIs package.json or arguments,
but process.argv[1]
could not be reduced to the executable's base name,
then proecess.argv[1]
is returned as-is.