Skip to content

Commit dac8fc0

Browse files
committed
feat: add cli checks related commands (listing)
1 parent 2b91d9b commit dac8fc0

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

index.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ const { Command } = require('commander')
22
const { getConfig } = require('./src/config')
33
const { projectCategories, dbSettings } = getConfig()
44
const { logger } = require('./src/utils')
5-
const { runAddProjectCommand, runWorkflowCommand, listWorkflowCommand } = require('./src/cli')
5+
const { runAddProjectCommand, runWorkflowCommand, listWorkflowCommand, listCheckCommand } = require('./src/cli')
66
const knex = require('knex')(dbSettings)
77

88
const program = new Command()
99

1010
const project = program.command('project').description('Manage projects')
1111

12-
// Project commands
12+
// Project related commands
1313
project
1414
.command('add')
1515
.description('Add a new project')
@@ -27,7 +27,7 @@ project
2727
}
2828
})
2929

30-
// Workflow commands
30+
// Workflows related commands
3131
const workflow = program.command('workflow').description('Manage workflows')
3232

3333
workflow
@@ -51,4 +51,22 @@ workflow
5151
.action((options) => {
5252
listWorkflowCommand(options)
5353
})
54+
55+
// Checks related commands
56+
const check = program.command('check').description('Manage checks')
57+
58+
check
59+
.command('list')
60+
.description('List all available checks')
61+
.action(async (options) => {
62+
try {
63+
await listCheckCommand(knex, options)
64+
} catch (error) {
65+
logger.error('Error running check:', error.message)
66+
process.exit(1)
67+
} finally {
68+
await knex.destroy()
69+
}
70+
})
71+
5472
program.parse(process.argv)

src/cli/checks.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { initializeStore } = require('../store')
2+
const { logger } = require('../utils')
3+
4+
async function listCheckCommand (knex, options = {}) {
5+
const { getAllComplianceChecks } = initializeStore(knex)
6+
const checks = await getAllComplianceChecks(knex)
7+
const implementedChecks = checks.filter(check => check['implementation_status'] === "completed")
8+
implementedChecks.forEach(check => {
9+
logger.log(`- ${check['code_name']}: ${check.title}`)
10+
})
11+
logger.log('------------------------------------')
12+
logger.log(`Implemented checks: ${implementedChecks.length}/${checks.length}.`)
13+
return implementedChecks
14+
}
15+
16+
module.exports = {
17+
listCheckCommand
18+
}
19+

src/cli/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const project = require('./project')
22
const workflows = require('./workflows')
3+
const checks = require('./checks')
34

45
module.exports = {
56
...project,
6-
...workflows
7+
...workflows,
8+
...checks
79
}

0 commit comments

Comments
 (0)