-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·203 lines (190 loc) · 6.21 KB
/
index.js
File metadata and controls
executable file
·203 lines (190 loc) · 6.21 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env node
"use strict";
const prog = require('caporal');
var chalk = require('chalk');
var figlet = require('figlet');
// var _ = require('lodash');
var packageInfo = require('./package.json');
var awUser = require('./api/user');
var awProject = require('./api/project');
var awInstance = require('./api/instance');
var awSchedule = require('./api/schedule');
var awScheduler = require('./api/scheduler');
var awSubscribe = require('./api/subscribe');
var util = require('./util');
var Configstore = require('configstore');
var pkg = require('./package.json')
const conf = require('./util/config')
const confStore = new Configstore(pkg.name, {foo: 'bar'});
util.clear()
console.log(
chalk.blue(
figlet.textSync('ApiWay', { horizontalLayout: 'full' })
)
);
prog
.version(packageInfo.version)
// the "login" command
.command('login', 'Login to apiway.io')
.help(`Login with OAuth`)
.alias('sign-in')
.option('-o, --oauth <oauth-provider>', 'OAuth provider (default: github)', ["github"])
.action((args, options, logger) => {
awUser.login()
// logger.info("Command 'order' called with:");
// logger.info("arguments: %j", args);
// logger.info("options: %j", options);
})
// the add command
.command('add', "Add a project")
.help('')
.option('-r, --repo <repo>', 'repository name')
.option('-o, --owner <owner>', 'A owner of a repository')
.action((args, options, logger) => {
if (options.repo == true) {
console.log(chalk.red('Need a repository name'));
showHelp()
}
if (options.owner == true) {
console.log(chalk.red('Need a owner name'));
showHelp()
}
awProject.add(options).then(() => {
})
})
// the project command
.command('project', "Project command for apiway.io")
.help('')
.option('-p, --projectId <projectId>', 'Specify a projectID')
.option('-l, --list', 'Show project list')
.option('-s, --subscriber <subscriber>',
'Set subscriber email to notify test result \n' +
' (e.g.) -s aaa@gmail.com,bbb@emil.com')
.option('-d, --delete <projectId>', 'Delete a project with projectId')
.option('-b, --branch <branch>', 'Change branch')
.action((args, options, logger) => {
if (!options.list && !options.delete
&& !options.projectId
&& !options.branch
&& !options.subscriber
&& !options.when && !options.interval && !options.cron) {
showHelp()
}
awProject.project(options).then((res) => {
}, (err) => {
showHelp(err)
})
})
// the run command
.command('run', "Project command for apiway.io")
.help('')
.option('-p, --project <projectFullName>', 'Project name (ex. bluehackmaster/apiway-cli')
.option('-l, --list', 'Show run history')
.option('-i, --instanceId <instanceId>', 'Show a information of instance')
.action((args, options, logger) => {
if (!options.project && !options.list && !options.instanceId) {
showHelp()
}
awInstance.run(options).then((res) => {
}, (err) => {
showHelp(err)
})
})
// the schedule command
.command('schedule', "Schedule command for apiway.io")
.help('')
.option('-p, --projectId <projectId>', 'Specify a projectID')
.option('-a, --add', 'Add a Schedule')
.option('-l, --list',
'Show all of user\'s Schedule\n' +
' $ apiway schedule -l \n' +
'Show all of Project\'s Schedule \n' +
' $ apiway schedule -p <projectId> -l \n' +
'Show all of Project\'s Schedule (Interactive Mode) \n' +
' $ apiway schedule -p -l \n')
.option('-s, --start', 'Start the Schedule')
.option('-e, --stop', 'Stop the schedule')
.option('-i, --scheduleId <scheduleId>',
'Show information of Schedule \n' +
' $ apiway schedule -i <scheduleId> \n' +
'Delete a Schedule \n' +
' $ apiway schedule -i <scheduleId> -d \n')
.option('-t, --interval <interval>',
'Set schedule with interval time \n' +
' (e.g.) 1h, 4h, 1d, 2d \n' +
'Range: 1h~24h, 1d~31d')
.option('-w, --when <when>',
'Set schedule with time \n' +
' (e.g.) 45m = 01:45, 02:45, ... , 24:45 \n' +
' 13h = 13:00 Sun, 13:00 Mon, ... , 13:00 Sat) \n' +
'Range: 1m ~ 59m, 1h~24h')
.option('-c, --cron <cron>',
'Set schedule with cron expression\n' +
' (e.g.) * */1 * * * = 01:00, 02:00 ... every hour \n' +
' * * */3 * * = every three days \n')
.option('-d, --delete <projectId>', 'Delete a project with projectId')
.action((args, options, logger) => {
if (!options.list && !options.delete
&& !options.projectId
&& !options.add
&& !options.scheduleId
&& !options.start
&& !options.stop
&& !options.when && !options.interval && !options.cron) {
showHelp()
}
confStore.set(conf.OPTIONS, options)
awSchedule.schedule(options).then((res) => {
}, (err) => {
showHelp(err)
})
})
// the scheduler command
.command('scheduler', "Scheduler command for apiway.io")
.help('')
.option('-l, --list', "Show all of Scheduler list")
.option('-i, --schedulerId <schedulerId>',
'Show information of Scheduler \n' +
' $ apiway scheduler -i <schedulerId> \n')
.option('-d, --delete <schedulerId>', 'Delete a Scheduler with schedulerID')
.action((args, options, logger) => {
if (!options.list && !options.delete
&& !options.schedulerId) {
showHelp()
}
confStore.set(conf.OPTIONS, options)
awScheduler.scheduler(options).then((res) => {
}, (err) => {
showHelp(err)
})
})
// the subscribe command
.command('subscribe', "Subscribe command for apiway.io")
.help('')
.option('-a, --add <email>', 'Add subscriber')
.option('-d, --delete <email>', 'Add subscriber')
.option('-p, --projectId <projectId>', 'Specify a projectID')
.option('-l, --list', 'Show subscriber list')
.action((args, options, logger) => {
if (!options.add && !options.delete
&& !options.projectId
&& !options.list) {
showHelp()
}
awSubscribe.subscribe(options).then((res) => {
}, (err) => {
showHelp(err)
})
})
prog.parse(process.argv);
function showHelp(err) {
if (err) {
console.log(chalk.red(err));
}
let argv = []
process.argv.forEach(arg => {
argv.push(arg)
})
argv[3] = '-h'
prog.parse(argv)
}