Socket
Socket
Sign inDemoInstall

main

Package Overview
Dependencies
2
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.15 to 0.0.16

examples/arguments.js

2

package.json
{
"name": "main",
"version": "0.0.15",
"version": "0.0.16",
"main": "index.js",

@@ -5,0 +5,0 @@ "repository": {

@@ -80,3 +80,3 @@ node-main

require('main')(module).run(function($) { $.cout('Hello World').exit(); });
require('main')(module).run(function($) { $.cout('Hello World'); });
require('main')(module).run(function($) { $.cout('Hello World'); });
```

@@ -121,2 +121,31 @@

##### `$.flags`
An object holding the all the values for the flags specified - it does not include arbitrary flags that were not defined. **Important Note** This does *not* include aliases, e.g.
```javascript
require('main')(module).flags({
foo: { alias: 'f' },
bar: { alias: 'b' }
})
.run(function($) {
$.cout($('f')); // valid, returns the value of flag "foo"
$.cout($('foo')); // valid, returns the same as above
$.cout($('bar')); // likewise for the "bar" flag.
$.cout($.flags); // object containing flags indexes by the given flags
});
```
If the above script is called with `./script -f hello -b world`, then the output would be:
```
hello
hello
world
{ foo: 'hello', bar: 'world' }
```
This is by design. If all flags, aliases, etc. are needed it's possible to access the raw optimist object's parsed flags & arguments with `$.optimist.argv`.
### Output Helpers

@@ -152,3 +181,3 @@

Returns a temporary file path - it does not create the file.
Returns a temporary file path - it does not create the file.

@@ -155,0 +184,0 @@ The options allow you to specify a prefix, suffix, and a directory. All of these are optional:

@@ -15,7 +15,16 @@ var extend = require('util')._extend;

self.optimist.argv = self.optimist.parse(process.argv);
// remove node/script path from pos args
self.optimist.argv._.splice(0, 2);
self.help = self.optimist.help();
self.args = self.optimist.argv._;
// set `self.flag`s to the values parsed (skip over $0 / "_" / others)
self.flags = {};
for (var argvKey in self.optimist.argv) {
if (typeof flags[argvKey] !== 'undefined') {
self.flags[argvKey] = self.optimist.argv[argvKey];
}
}
self.help = self.optimist.help(); // pull out the static help message
self.args = self.optimist.argv._; // pull out the positional arguments
//-------------------------------------------

@@ -52,3 +61,3 @@

Read from stdin in it's entirety, and return a string once finished.
Do not use self if you are dealing with large amounts of data from stdin.
Do not use this if you are dealing with large amounts of data from stdin.

@@ -55,0 +64,0 @@ @param {function} callback - Contains the stdin string

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc