-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.js
More file actions
82 lines (66 loc) · 2.15 KB
/
cmd.js
File metadata and controls
82 lines (66 loc) · 2.15 KB
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
'use strict';
module.exports = cmd;
/**
* @param whaler
*/
async function cmd (whaler) {
await domains(whaler);
await publish(whaler);
await unpublish(whaler);
}
/**
* @param whaler
*/
async function domains (whaler) {
(await whaler.fetch('cli')).default
.command('domains [app]')
.description('Show published domains', {
app: 'Application name'
})
.option('-f, --format <FORMAT>', 'The output format (txt or json) [default: "txt"]')
.action(async (app, options) => {
const response = await whaler.emit('haproxy:domains', { app });
if ('json' == options.format) {
console.log(JSON.stringify(response, null, 2));
} else {
const table = (await whaler.fetch('cli-table')).default({
head: [ 'Application name', 'Domain', 'Regex' ]
});
console.log('\n' + table.render(response) + '\n');
}
})
.ignoreOutEndLine(true);
}
/**
* @param whaler
*/
async function publish (whaler) {
(await whaler.fetch('cli')).default
.command('domains:publish <domain> [app]')
//.alias('publish')
.description('Publish app domain', {
app: 'Application name',
domain: 'Domain to publish'
})
.option('--regex', 'Match domain as regex')
.action(async (domain, app, options, util) => {
app = util.prepare('name', app);
await whaler.emit('haproxy:domains:publish', { app, domain, regex: options.regex });
whaler.info('Domain `%s` published to `%s` app.', domain, app);
});
}
/**
* @param whaler
*/
async function unpublish (whaler) {
(await whaler.fetch('cli')).default
.command('domains:unpublish <domain>')
//.alias('unpublish')
.description('Unpublish app domain', {
domain: 'Domain to unpublish'
})
.action(async (domain, options) => {
const app = await whaler.emit('haproxy:domains:unpublish', { domain });
whaler.info('Domain `%s` unpublished from `%s` app.', domain, app);
});
}