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/index.js:
#!/usr/bin/env node var cmd = argv: processargv ; console;// Windows: => "C:\\Users\\user\\AppData\\Roaming\\npm\\node_modules\\my-cli\\bin\\index.js"// OS X or Linux: => "my-cli" console;// 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.