argv-one

1.0.1 • Public • Published

argv-one

cross-platform helper for process.argv[1]

npm module Build Status Build status

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.

Package Sidebar

Install

npm i argv-one

Weekly Downloads

3

Version

1.0.1

License

BSD-2-Clause

Last publish

Collaborators

  • jokeyrhyme