feat: WIP new utils to query events from CLI, fix #357

This commit is contained in:
lesion 2024-02-18 22:36:46 +01:00
parent 2c316ad613
commit cf5e8bc1f7
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 31 additions and 0 deletions

View file

@ -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
View 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