1 | 'use strict';
|
2 |
|
3 | const commands = require('./commands');
|
4 |
|
5 | let args = process.argv.slice(2);
|
6 |
|
7 | let argly = require('argly')
|
8 | .createParser({
|
9 | '--help': {
|
10 | type: 'string',
|
11 | description: 'Show this help message'
|
12 | },
|
13 | '--dir -d': {
|
14 | type: 'string',
|
15 | description: 'Directory that contains the DynomoDB migrations'
|
16 | },
|
17 | '--migration -m': {
|
18 | type: 'string',
|
19 | description: 'Name of the migration to create'
|
20 | }
|
21 | })
|
22 | .usage('Usage: dynograte [options]')
|
23 | .example(
|
24 | 'Create a migration file',
|
25 | 'dynograte create --path ~/Proj/dynomodb-migrations --migration update-users-table')
|
26 | .validate(function(result) {
|
27 | if (result.help) {
|
28 | this.printUsage();
|
29 | process.exit(0);
|
30 | }
|
31 | })
|
32 | .onError(function(err) {
|
33 | this.printUsage();
|
34 | console.error(err);
|
35 | process.exit(1);
|
36 | });
|
37 |
|
38 | if (args.length < 1) {
|
39 | argly.printUsage();
|
40 | process.exit(1);
|
41 | } else {
|
42 | let command = commands[args[0]];
|
43 | if (!command) {
|
44 | argly.printUsage();
|
45 | process.exit(1);
|
46 | } else {
|
47 | args.shift();
|
48 | command(argly.parse(args));
|
49 | }
|
50 | }
|