-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
87 lines (77 loc) · 2.22 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
const { Command } = require('commander')
const { getConfig } = require('./src/config')
const { projectCategories, dbSettings } = getConfig()
const { logger } = require('./src/utils')
const { runAddProjectCommand, runWorkflowCommand, listWorkflowCommand, listCheckCommand, runCheckCommand } = require('./src/cli')
const knex = require('knex')(dbSettings)
const program = new Command()
const project = program.command('project').description('Manage projects')
// Project related commands
project
.command('add')
.description('Add a new project')
.option('--name <name>', 'Name of the project')
.option('--github-urls <urls...>', 'GitHub URLs of the project')
.option('--category <category>', `Category of the project. Choose from: ${projectCategories.join(', ')}`)
.action(async (options) => {
try {
await runAddProjectCommand(knex, options)
} catch (error) {
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
}
})
// Workflows related commands
const workflow = program.command('workflow').description('Manage workflows')
workflow
.command('run')
.description('Run a workflow')
.option('--name <name>', 'Name of the workflow')
.action(async (options) => {
try {
await runWorkflowCommand(knex, options)
} catch (error) {
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
}
})
workflow
.command('list')
.description('List all available workflows')
.action((options) => {
listWorkflowCommand(options)
})
// Checks related commands
const check = program.command('check').description('Manage checks')
check
.command('list')
.description('List all available checks')
.action(async (options) => {
try {
await listCheckCommand(knex, options)
} catch (error) {
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
}
})
check
.command('run')
.description('Run a check')
.option('--name <name>', 'Name of the check')
.action(async (options) => {
try {
await runCheckCommand(knex, options)
} catch (error) {
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
}
})
program.parse(process.argv)