This repository was archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (59 loc) · 1.7 KB
/
index.js
File metadata and controls
64 lines (59 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Load a program definition into a new program assigning the definition
* properties to the program.
*
* Properties are passed by reference so if you modify the definition the
* program is also modified.
*
* @function load
* @param {Object} def the program definition.
* @param {Object} [opts] program options.
*
* @returns a new program.
*/
function load(def) {
var Program = require('./lib/program')
, prg = new Program();
for(var k in def) {
prg[k] = def[k];
}
return prg;
}
/**
* Load a program definition into a new program assigning the definition
* properties to the program.
*
* Properties are passed by reference so if you modify the definition the
* program is also modified.
*
* The callback function signature is `function(err, req)` where `req` is a
* request object that contains state information for program execution.
*
* Plugins may decorate the request object with pertinent information that
* does not affect the `target` object that receives the parsed arguments.
*
* @function run
* @param {Object} src the source program or definition.
* @param {Array} argv the program arguments.
* @param {Object} [runtime] runtime configuration.
* @param {Function} cb callback function.
*
* @returns a new program.
*/
function run(src, argv, runtime, cb) {
var Program = require('./lib/program')
, runner = require('./lib/run');
if(!(src instanceof Program)) {
src = load(src);
}
runner.call(src, argv, runtime, cb);
}
var cli = {};
cli.run = run;
cli.load = load;
cli.camelcase = function() {
// lazy require
var camel = require('cli-argparse').camelcase;
return camel.apply(this, arguments);
}
module.exports = cli;