1 | 'use strict'
|
2 |
|
3 |
|
4 |
|
5 | const yargs = require('./yargs')
|
6 |
|
7 | Argv(process.argv.slice(2))
|
8 |
|
9 | module.exports = Argv
|
10 |
|
11 | function Argv (processArgs, cwd) {
|
12 | const argv = yargs(processArgs, cwd, require)
|
13 | singletonify(argv)
|
14 | return argv
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function singletonify (inst) {
|
25 | Object.keys(inst).forEach((key) => {
|
26 | if (key === 'argv') {
|
27 | Argv.__defineGetter__(key, inst.__lookupGetter__(key))
|
28 | } else {
|
29 | Argv[key] = typeof inst[key] === 'function' ? inst[key].bind(inst) : inst[key]
|
30 | }
|
31 | })
|
32 | }
|