-
Notifications
You must be signed in to change notification settings - Fork 0
/
patrick.js
executable file
·108 lines (90 loc) · 2.74 KB
/
patrick.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
#!/usr/bin/env node
var pkg = require('./package.json'),
program = require('commander'),
fs = require('fs'),
path = require('path'),
color = require('colors'),
readline = require('readline-sync'),
Cfg = require('./lib/cfg'),
Client = require('./lib/client'),
Table = require('cli-table'),
configDir = process.env['HOME']+'/.patrick',
tokenFile = configDir+'/token',
configFile = configDir+'/config.json'
// Config
var cfg = new Cfg(configFile)
if (!fs.existsSync(configFile)) {
console.log("Hello fellow developer,".yellow)
console.log("It seems it is the first time you launch patrick".yellow)
var url = readline.question("Would you please enter the patrick server url ? : ")
cfg.url = url
cfg.save()
console.log("Thank you, the configuration is save at ".green, configFile)
console.log("Now you can enjoy patrick".green)
process.exit(0)
}
// Load config
cfg.load();
// Load client
var client = new Client(cfg.url, tokenFile)
program
.version(pkg.version)
.description('Node client for patrick')
program
.command('run <task>')
.description('Execute a server task')
.action(function (task) {
client.run(task)
});
program
.command('list')
.alias('l')
.description('List available tasks')
.action(function () {
client.getTasks(function (res, body) {
var tasks = body.reduce(function (arr, t) {
arr.push([t.name, t.description])
return arr
}, [])
var table = new Table({})
table.push.apply(table, tasks)
console.log("Here is the tasks list available from the server.".magenta)
console.log("You can execute them with the `run` command. Ex: patrick run <task>".magenta)
console.log(table.toString())
})
});
program
.command('logs')
.description('Display logs')
.action(function () {
client.logs(function (res, body) {
console.log(body)
})
});
program
.command('login')
.description('Login to the patrick server')
.action(function () {
client.login(function () {
console.log("You are logged in!".green)
})
});
program
.command('logout')
.description('Logout from the patrick server')
.action(function () {
client.logout()
console.log("You are logged out!".green)
});
program
.command('server-version')
.description('Display the patrick server version')
.action(function () {
client.version(function (res, body) {
console.log(body)
})
});
program.parse(process.argv)
if (!process.argv.slice(2).length) {
program.help()
}