-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·150 lines (133 loc) · 4.9 KB
/
index.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/local/bin/node
let chalk = require('chalk')
let program = require('commander')
const vorpal = require('vorpal')()
let config = require('./Configuration/config')
let table = require('./commands/command.table')
var os = require('os'),
clui = require('clui')
vorpal
.command('dev [xyzCommandLineArgs...]', 'run according to config file locally. when -x is enabled, you can pass in command line args like `xyz-name foo` to override the name in ADMIN NODE. Note that there is no `--xyz` in this case.')
.option('-c, --config <conf>', 'xyz config file to use. if not, will use ./xyzrc.json')
.option('-x, --xyzadmin', 'lunch an xyz core instance inside the cli process')
.option('-a --appendadmin', 'add admin node to all clients using --xyz-nodes. will work only with -x')
.option('-e, --errlog', 'log additional info from a process while it is being lunched')
.option('-d, --delay <value>', 'delay between creating instances. default is 500ms')
.action(function (args, callback) {
require('./commands/command.dev')(args, () => {
table()
callback()
})
})
vorpal
.command('ls', 'list of all instances currently active')
.alias('list')
.action(function (args, callback) {
table()
callback()
})
vorpal
.command('inspect <identifier>', 'show details of a node. identifier must be the name or id')
.alias('insp')
.action(function (args, callback) {
config.inspect(args.identifier, false, (err, data) => {
this.log(data)
callback()
})
})
vorpal
.command('inspectSelf', 'show the xyz-core insatance in curretn cli process. works only with -x option after dev command')
.alias('inspS')
.action(function (args, callback) {
this.log(config.getAdmin())
callback()
})
vorpal
.command('inspectJSON <identifier>', 'show details of a node. identifier must be the name or id')
.alias('inspJ')
.action(function (args, callback) {
config.inspect(args.identifier, true, (err, data) => {
this.log(data)
callback()
})
})
vorpal
.command('kill <identifier>', 'kill a node. identifier must be the name or id')
.action(function (args, callback) {
config.kill(args.identifier, (err) => {
if (err) console.log(chalk.bold.red(err))
else console.log(chalk.bold.green('Killed'))
callback()
})
})
// TODO support additional paramss
vorpal
.command('duplicate <identifier>', 'duplicate a node. identifier must be the name or id')
// .option('-p, -params <cmdParams>', 'additional command line parameters appended to the spawn args')
.alias('dup')
.action(function (args, callback) {
config.duplicate(args.identifier, (err) => {
if (err) console.log(chalk.bold.red(err))
else console.log(chalk.bold.green('Duplicated'))
callback()
})
})
// TODO support additional paramss
vorpal
.command('restart <identifier>', 'restart a given node. identifier must be the name or id')
// .option('-p, -params <cmdParams>', 'additional command line parameters appended to the spawn args')
.alias('rest')
.action(function (args, callback) {
config.restart(args.identifier, (err) => {
if (err) console.log(chalk.bold.red(err))
else console.log(chalk.bold.green('Restarted'))
callback()
})
})
vorpal
.command('top', 'show network and memory usage of nodes')
.action(function (args, callback) {
require('./commands/command.top')(callback, vorpal)
})
vorpal
.command('log <identifier>', 'show the live content of the log file of a service')
.action(function (args, callback) {
require('./commands/command.tail')(args.identifier, callback)
})
vorpal
.command('msg <identifier> <servicePath> [payload]', 'send message to a node. Must run dev before using this')
.alias('call')
.action(function (args, callback) {
require('./commands/command.msg')(args, callback)
})
vorpal
.command('single <file> [params...]', 'call a single node with an admin on top of it')
.action(function (args, callback) {
require('./commands/command.single')(args, callback)
})
console.log(chalk.bold.green(`
_ _ ___________ _____ __ ____ ________
| \ | | _ | _ \\ ___| \\ \\ / /\\ \\ / /___ /
| \\| | | | | | | | |__ ______\\ V / \\ V / / /
| . \` | | | | | | | __|______/ \\ \\ / / /
| |\\ \\ \\_/ / |/ /| |___ / /^\\ \\ | | ./ /___
\\_| \\_/\\___/|___/ \\____/ \\/ \\/ \\_/ \\_____/
\n`) + chalk.bold.blue('microservice microframework for NodeJS\n'))
//
vorpal
.delimiter('xyz > ')
.parse(process.argv)
.show()
// catches ctrl+c event
process.on('SIGINT', () => {
console.log(chalk.bold.red(`[SIGINT] CLI Process About to exit.`))
config.clean()
process.exit()
})
// catches uncaught exceptions
process.on('uncaughtException', (e, ee) => {
console.log(chalk.bold.red(`[uncaughtException] CLI Process About to exit.\n ${e}`))
config.clean()
process.exit()
})
module.exports = require('./commands/test')