-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkaabah.js
47 lines (40 loc) · 1.05 KB
/
kaabah.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
#!/usr/bin/env node
const program = require('commander')
const fs = require('fs')
const shell = require('shelljs')
const makeDebug = require('debug')
const debug = makeDebug('kaabah')
function log (message, type = 'info') {
let color = '\x1b[0m'
switch (type) {
case 'error':
color = '\x1b[31m'
break
case 'warn':
color = '\x1b[33m'
break
default:
}
console.error('%s[kargo] %s\x1b[0m', color, message)
}
function init (backend) {
debug('[subcommand] init')
if (! fs.existsSync(backend)) {
log('The ' + backend + ' file does not exist', 'error')
shell.exit(1)
}
if (shell.cp(backend, 'backend.tf').code != 0) {
log('An error has occured while copying ' + backend, 'error')
shell.exit(1)
}
if (shell.exec('terraform init').code !== 0) {
log('An error has occured while initializing Terraform', 'error')
shell.exit(1)
}
}
program
.version(require('./package.json').version)
program
.command('init <backend>')
.action((backend) => init(backend))
program.parse(process.argv)