1 | #!/usr/bin/env node
|
2 |
|
3 | var exists = require('fs').existsSync,
|
4 | program = require('commander'),
|
5 | resolve = require('path').resolve,
|
6 | spawn = require('child_process').spawn,
|
7 | config = require('nconf'),
|
8 | fs = require("fs"),
|
9 | path = require("path"),
|
10 | logger = require('../lib/logger');
|
11 |
|
12 | /*
|
13 | |--------------------------------------------------------------------------
|
14 | | Help
|
15 | |--------------------------------------------------------------------------
|
16 | */
|
17 | program.on('--help', function(){
|
18 | console.log(' Commands:');
|
19 | console.log();
|
20 | console.log(' bstalk --version Print version');
|
21 | console.log(' bstalk config Create config file');
|
22 | console.log(' bstalk openconfig Open config file for edition');
|
23 | console.log(' bstalk repos Display list of all repositories');
|
24 | console.log(' bstalk create <repo> [color] Create a git <repo> with specified [color]');
|
25 | console.log(' bstalk deploy <repo> <env> [comment] Deploy environment last revision <env> on <repo>');
|
26 | console.log();
|
27 | });
|
28 |
|
29 | /*
|
30 | |--------------------------------------------------------------------------
|
31 | | Program
|
32 | | Forward to sub commands (git style)
|
33 | |
|
34 | |--------------------------------------------------------------------------
|
35 | */
|
36 | program
|
37 | .version(require('../package').version)
|
38 | .usage('<command> [options]');
|
39 |
|
40 | program.parse(process.argv);
|
41 | if (!program.args.length) program.help();
|
42 |
|
43 | var cmd = program.args[0];
|
44 | var args = process.argv.slice(3);
|
45 | var bin = resolve(__dirname, 'bstalk-' + cmd);
|
46 |
|
47 | if (!exists(bin)) {
|
48 | logger.log('There is no `%s` command.', cmd);
|
49 | console.log();
|
50 | program.help();
|
51 | }
|
52 |
|
53 | // Spawn a new, forwarded child process for the subcommand.
|
54 | var child = spawn(bin, args, { stdio: 'inherit' });
|
55 | child.on('close', process.exit.bind(process));
|