This repository has been archived by the owner on Aug 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
/
duo
executable file
·92 lines (69 loc) · 1.56 KB
/
duo
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
/**
* Module dependencies.
*/
var exists = require('fs').existsSync;
var search = require('path-search');
var Logger = require('stream-log');
var spawn = require('win-fork');
var path = require('path');
var resolve = path.resolve;
/**
* Logger.
*/
var logger = new Logger(process.stderr);
/**
* Error.
*/
logger.type('error', '31m', function () {
logger.end();
process.exit(1);
});
/**
* Resolve.
*/
var args = process.argv.slice(2);
/**
* Extract the first argument to test as a sub-command.
*/
var command = args.shift();
/**
* If we're not talking about a sub-command, fall back on `_duo`.
*/
var fallback = resolve(__dirname, '_duo');
/**
* Rebuild the args array correctly based on the command/subcommand/etc.
*/
if (command && subcommand(command)) {
var paths = [__dirname].concat(process.env.PATH.split(':'));
var subcmd = search(paths, 'duo-' + command);
if (!subcmd) logger.error('duo-' + command + '(1) not found');
args.unshift(subcmd);
} else if (command) {
args.unshift(fallback, command);
} else {
args.unshift(fallback);
}
/**
* Add the necessary node flag.
*/
if (!require('has-generators')) args.unshift('--harmony-generators');
/**
* Spawn.
*/
var proc = spawn(process.execPath, args, { stdio: 'inherit' });
/**
* Exit.
*/
proc.on('exit', function (code) {
process.exit(code);
});
/**
* Checks if an argument could be a valid sub-command.
*/
function subcommand(arg) {
if (path.extname(arg)) return false;
if (arg[0] === '-') return false;
if (exists(arg)) return false;
return true;
}