![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
main
Advanced tools
Readme
Runs a block of code if a script is called directly as in calling node script
. It will not call the block of code if the script has been required in another module as in require('script')
.
node-main utilizes optimist for argument parsing and provides other tools that are useful for when working with command line scripts.
npm install --save main
Once required, you can chain the functions below.
Note that the module
part is required. This is to properly allow nesting of modules. e.g.
script1
contains require('main')(module)
script2
requires script1
, and implements it's own require('main')(module)
.We expect that when running script2
from the command line that it will only call the main function of script2
, and not call the main function of script1
.
For the time being, this is required until I or someone else figures out a way around it. Read the caching section of the Node Modules API for more information.
An optional message to append to the top of flags that can describe how the script should be invoked, e.g.
Usage: ./script [flags] <posArg1> <posArg2>
Flags do not have to be specified in this string. Usage for flags are automatically generated based on the options provided (see below) and will appear after this usage message.
options
follows the optimist format for options, but groups them together, e.g.:
require('main')(module).flags({
f: { alias: 'flag' },
t: { alias: 'secondFlag' },
d: { demand: true },
// ...
})
fn
is the callback that will be invoked when the script is ran directly from a terminal. It can take the following parameters:
fn(argv, exit, help)
argv
is the parsed optimist argv objectexit
is a helper function that can be used to exit the script. It follows the form exit(exitCode, optionalMessage)
. If no exit code if provided, it will exit with 0 (success).help
is the usage information if the need arises to explicitly display it.Refer to the following script as sentence.js
#!/usr/bin/env node
exports.sentence = function(name, word1, word2) {
return name + ',' + word1 + ' ' + word2 + '.';
};
require('main')(module)
.usage('Usage:\n node test.js [flags] <word1> <word2>')
.flags({
n: { alias: 'name', demand: true }
})
.run(function(argv, exit, help) {
// exit if there aren't two words (positional arguments)
if (argv._.length !== 2) { exit(1, help); }
var word1 = argv._[0],
word2 = argv._[1];
exports.sentence(argv.name, word1, word2);
});
Running from the terminal ($? indicates exit status):
> node sentence.js --name Nolan sit down
Nolan, sit down.
> $?
0 (success)
> node sentence.js
# (prints out help & usage information. name / words are not defined)
> $?
1 (failure)
Using the module from another script will not execute the code in main:
var scriptAbove = require('./scriptAbove');
console.log(scriptAbove.sentence('Nolan', 'sit', 'down'));
When installing, make sure to use the --save
option and/or specify the version in your package.json
dependencies. This package is undergoing some heavy changes at the moment and new versions may be radically different from previous releases. This type of business will stop once it reaches 0.1.0.
FAQs
main entry point
We found that main demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.