mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 08:32:23 +01:00
feat: WIP new utils to query events from CLI, fix #357
This commit is contained in:
parent
2c316ad613
commit
cf5e8bc1f7
2 changed files with 31 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
const pkg = require('../package.json')
|
||||
const path = require('path')
|
||||
const usersCLI = require('./cli/users')
|
||||
const eventsCLI = require('./cli/events')
|
||||
|
||||
process.env.cwd = process.env.GANCIO_DATA || path.resolve('./')
|
||||
|
||||
|
@ -30,6 +31,7 @@ require('yargs')
|
|||
}})
|
||||
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
|
||||
.command(['users'], 'Manage users', usersCLI)
|
||||
.command(['events'], 'Manage events', eventsCLI)
|
||||
.help('h')
|
||||
.alias('h', 'help')
|
||||
.epilog('Made with ❤ by underscore hacklab - https://gancio.org')
|
||||
|
|
29
server/cli/events.js
Normal file
29
server/cli/events.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
let db
|
||||
function _initializeDB () {
|
||||
const config = require('../config')
|
||||
if (config.status !== 'CONFIGURED') {
|
||||
console.error(`> Cannot run CLI before setup (are you in the correct path?)`)
|
||||
process.exit(1)
|
||||
}
|
||||
config.log_level = 'error'
|
||||
db = require('../api/models/index')
|
||||
return db.initialize()
|
||||
}
|
||||
|
||||
async function list () {
|
||||
await _initializeDB()
|
||||
const { Event } = require('../api/models/models')
|
||||
const events = await Event.findAll()
|
||||
console.log()
|
||||
events.forEach(u => console.log(`${u.id}\ttitle: ${u.title}\tstart_datetime: ${u.start_datetime}\tend_datetime: ${u.end_datetime}`))
|
||||
console.log()
|
||||
await db.close()
|
||||
}
|
||||
|
||||
const eventsCLI = yargs => yargs
|
||||
.command('list', 'List all events', list)
|
||||
.recommendCommands()
|
||||
.demandCommand(1, '')
|
||||
.argv
|
||||
|
||||
module.exports = eventsCLI
|
Loading…
Reference in a new issue