-
Notifications
You must be signed in to change notification settings - Fork 117
/
fly.js
executable file
·133 lines (109 loc) · 3.25 KB
/
fly.js
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env node
var Liftoff = require('liftoff')
, interpret = require('interpret')
, v8flags = require('v8flags')
, semver = require('semver')
, cliPackage = require('../package')
, nopt = require('nopt')
, format = require('util').format;
var knownOptions = {
'flightplan': String,
'username': String,
'debug': Boolean,
'color': Boolean,
'version': Boolean,
'help': Boolean
};
var shortHands = {
'f': ['--flightplan'],
'u': ['--username'],
'd': ['--debug'],
'C': ['--no-color'],
't': ['--targets'],
'T': ['--tasks'],
'v': ['--version'],
'h': ['--help']
};
var options = nopt(knownOptions, shortHands, process.argv, 2);
if(options.help) {
process.stdout.write(
'\n' +
' Usage: fly [task:]target [options]\n\n' +
' Options:\n\n' +
' -f, --flightplan <file> path to flightplan\n' +
' -u, --username <name> user for connecting to remote hosts\n' +
' -d, --debug enable debug mode\n' +
' -C, --no-color disable color output\n' +
' -t, --targets output available targets\n' +
' -T, --tasks output available tasks\n' +
' -v, --version output the version number\n' +
' -h, --help output usage information\n' +
'\n'
);
process.exit(1);
}
if(options.version) {
process.stdout.write(format('%s\n', cliPackage.version));
process.exit(1);
}
var task;
var target = options.argv.remain.length ? options.argv.remain[0] : null;
if(target && target.indexOf(':') !== -1) {
target = target.split(':');
task = target[0];
target = target[1];
}
var cli = new Liftoff({
name: 'flightplan',
processTitle: 'Flightplan',
configName: 'flightplan',
extensions: interpret.jsVariants,
v8flags: v8flags
});
cli.on('requireFail', function(name) {
process.stderr.write(format('Error: Unable to load module "%s"\n', name));
process.exit(1);
});
var invoke = function(env) {
if(!env.configPath) {
process.stderr.write(format('Error: %s not found\n', (options.flightplan || 'flightplan.js')));
process.exit(1);
}
if(!env.modulePath) {
process.stderr.write(format('Error: Local flightplan package not found in %s\n', env.cwd));
process.exit(1);
}
if(!semver.satisfies(env.modulePackage.version, '>=0.5.0')) {
process.stderr.write('Error: local flightplan package version should be >=0.5.0\n');
process.exit(1);
}
process.chdir(env.configBase);
require(env.configPath); // eslint-disable-line global-require
var instance = require(env.modulePath); // eslint-disable-line global-require
if(options.targets) {
process.stdout.write(
'Available targets:\n' +
' ' + instance.availableTargets().join('\n ') + '\n'
);
process.exit(0);
}
if(options.tasks) {
process.stdout.write(
'Available tasks:\n' +
' ' + instance.availableTasks().join('\n ') + '\n'
);
process.exit(0);
}
if(!target) {
process.stderr.write(
'Error: No target specified. Use `--help` for more information\n\n' +
'Available targets:\n' +
' ' + instance.availableTargets().join('\n ') + '\n'
);
process.exit(1);
}
instance.run(task, target, options);
};
cli.launch({
configPath: options.flightplan
}, invoke);