UNPKG

1.15 kBJavaScriptView Raw
1/**
2 * @group Command line
3 * The command line interface
4 */
5
6module.exports = function(app, cli) {
7
8 cli.go = function(argv) {
9 // Shortcuts
10 if (argv[2] === 'c') argv[2] = 'console';
11 if (argv[2] === 's') argv[2] = 'server';
12 if (argv[2] === 'r') argv[2] = 'runner';
13
14 this.parse(argv);
15 if (argv.length === 2) this.help();
16 };
17
18 cli
19 .version(require(app.path('package')).version)
20 .option('-e, --env [env]', 'Environment to start in [develompent]');
21
22 cli
23 .on('env', function(env) {
24 app.set('env', env);
25 });
26
27 /**
28 * Starts a server.
29 */
30
31 cli
32 .command('server [port] [..]')
33 .description('Starts the server (alias: "s")')
34 .action(function(port, flags) {
35 require('../lib/runner')(app, port, flags);
36 });
37
38 cli
39 .command('console')
40 .description('Opens a console (alias: "c")')
41 .action(function() {
42 app.loadConsole();
43 require('repl').start({});
44 });
45
46 cli
47 .command('runner [cmd]')
48 .description('Runs a command (alias: "r")')
49 .action(function(command) {
50 console.log('run');
51 global.app = app.load();
52 eval(command);
53 });
54};