
Product
Introducing Supply Chain Attack Campaigns Tracking in the Socket Dashboard
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.
Visit application methods that map directly to command line arguments and emit events for flags.
Visit application methods that map directly to command line arguments and emit events for flags.
Install with npm
$ npm i visit-args --save
First, an example, so the following docs make sense.
var argv = require('minimist');
var cli = require('visit-args');
// see the `app` example in `./examples/app.js` for details
var App = require('./examples/app');
var app = new App();
cli.on('set', function (key, val) {
// do stuff with key/val
});
cli.on('get', function (key, val) {
// do stuff with key/val
});
cli.visit(app, argv(['--set=a', '--get=a']));
How this works
The idea is that app is an object with methods on it, and when a command line flag matches the name of a method on app, that method is called and is passed any additional arguments related to that method call (that's the tricky part: "additional arguments". Which is what this lib does - figure out how to invoke that method with the right arguments...)
Method arguments
This brings up the question: "What is passed to the method when it's called, if all we have is a command line flag?". That's a good question. This is easiest to explain by way of examples. Let's say you pass the following flag:
$ --a=b
Minimist would parse this to {a: 'b'}. Next, if you're application happens to have a method named a, then visit-args would invoke the method and pass b to it. A more meaningful example might be something like:
$ --del=foo
Which would invoke the del method on app, with the foo argument. In other words:
app.del('foo');
If, more often than not, your methods need more information than just a string or boolean to be able to take any kind of meaningful action, then it's worth considering using a library like expand-args, which will post-process arguments after minimist, but before visit-args, so that the following is possible:
$ --set=a:b
Which would invoke the following on app:
app.set('a', 'b');
See expand-args and expand-object for more details.
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on August 07, 2015.
FAQs
Visit application methods that map directly to command line arguments and emit events for flags.
We found that visit-args 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
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.

Security News
Node.js 25.4.0 makes require(esm) stable, formalizing CommonJS and ESM compatibility across supported Node versions.