Socket
Socket
Sign inDemoInstall

get-options

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1 to 1.0.0

docs/advanced-settings.md

2

index.js

@@ -309,3 +309,3 @@ #!/usr/local/bin/node --es_staging

if("first-only" === noAliasPropagation)
name = option.longNames[0];
name = option.longNames[0] || option.shortNames[0];

@@ -312,0 +312,0 @@ /** camelCase? */

{
"name": "get-options",
"version": "0.0.1",
"version": "1.0.0",
"description": "JavaScript's answer to getopts. Simple, obvious, and direct.",

@@ -5,0 +5,0 @@ "keywords": ["CLI", "getopt", "getopts", "options", "argv", "command-line", "configuration", "config"],

@@ -9,17 +9,26 @@ GetOptions

* Don't mind writing your own documentation
* Are just interested in lifting options so that this...
<code>$ program <b><ins>--log-path</ins> <ins>/var/log/stuff.txt</ins></b> generate all-files <b><ins>--verbose</ins></b></code>
<br/>... gets filtered like this:
<code>$ program generate all-files</code>
<br/>... with all the helpful stuff sorted neatly in one little object:
* Prefer a hands-on approach without pointless array-fiddling
This lets you extract options so this...
<pre><code>$ program <b>--log-path <ins>/var/log/stuff.txt</ins></b> generate all-files <b><ins>--verbose</ins></b></code></pre>
... gets filtered down to this:
<pre><code>$ program generate all-files</code></pre>
... with everything neatly sorted into one little object:
```js
let result = {
options: {
logPath: "/var/log/stuff.txt",
verbose: true
},
argv: [
"generate",
"all-files"
]
options: {
logPath: "/var/log/stuff.txt",
verbose: true
},
argv: [
"generate",
"all-files"
]
};

@@ -36,7 +45,7 @@ ```

getOpts(process.argv, {
"-v, --verbose": "",
"-l, --log-level": "[level]",
"-p, --log-path": "<path>",
"-s, --set-config": "<name> <value>",
"-f, --files": "<search-path> <variadic-file-list...>"
"-v, --verbose": "",
"-l, --log-level": "[level]",
"-p, --log-path": "<path>",
"-s, --set-config": "<name> <value>",
"-f, --files": "<search-path> <variadic-file-list...>"
});

@@ -47,3 +56,3 @@ ```

Short and long forms of each defined option, separated by commas.
**Right column:**

@@ -65,3 +74,3 @@ Arguments each option takes, if any.

<code>program <b>--files <kbd>/search/path</kbd> <kbd>1.jpg</kbd> <kbd>2.txt</kbd> <kbd>3.gif</kbd></b> <b>--log-path <kbd>/path/to/</kbd></b> subcommand param <b>--verbose</b></code>
<pre><code>program <b>--files <ins>/search/path</ins> <ins>1.jpg</ins> <ins>2.txt</ins> <ins>3.gif</ins></b> <b>--log-path <ins>/path/to/</ins></b> subcommand param <b>--verbose</b></code></pre>

@@ -71,8 +80,8 @@ ... would yield:

let result = {
argv: ["subcommand", "param"],
options: {
files: ["/search/path", "1.jpg", "2.txt", "3.gif"],
logPath: "/path/to",
verbose: true
}
argv: ["subcommand", "param"],
options: {
files: ["/search/path", "1.jpg", "2.txt", "3.gif"],
logPath: "/path/to",
verbose: true
}
};

@@ -91,5 +100,5 @@ ```

let subcommands = {
generate: function(whichFiles){
console.log("Let's generate... " + whichFiles);
}
generate: function(whichFiles){
console.log("Let's generate... " + whichFiles);
}
};

@@ -110,11 +119,18 @@

Further reading
---------------
Notes
-----
* This is pure JavaScript, meaning it's not reliant on Node to work. Feel free to use it in a browser environment or whatever.
* The array that's passed to the function isn't modified. If you want to overwrite the values stored in `process.argv`, you can do so by assignment:
```js
process.argv = result.argv;
```
This is by design. It's not reasonable to assume developers will expect the contents of the array to be automatically shifted as options are being plucked from it.
I've broken the more convoluted documentation into different files, in an effort to keep this readme file terse:
* **[Advanced Options](docs/advanced-settings.md):** Covers additional features not detailed here
* **[Bundling](docs/bundling.md):** Describes how `getOpts` parses bundled short-options like `-cyfaws`
Reminders
---------
* This is pure JavaScript, so it's not reliant on Node to work. Feel free to use it in a browser environment or whatever.<br/><br/>
* The array that's passed to the function isn't modified. If you want to overwrite the values stored in `process.argv`, do so by assignment:
<pre><code>process.argv = result.argv;</code></pre>
This is by design. It's not reasonable to assume developers will expect the contents of the array to be automatically shifted as options are being plucked from it.<br/><br/>
* As you'd expect, the first two values in `process.argv` contain the paths of the Node executable and the currently-running script.

@@ -121,0 +137,0 @@ These have been omitted from the examples documented here (perhaps misleadingly, but done so for brevity's sake).

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc