From cf5e8bc1f744d7d84d890f7d507fd865f8249b27 Mon Sep 17 00:00:00 2001 From: lesion Date: Sun, 18 Feb 2024 22:36:46 +0100 Subject: [PATCH] feat: WIP new utils to query events from CLI, fix #357 --- server/cli.js | 2 ++ server/cli/events.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 server/cli/events.js diff --git a/server/cli.js b/server/cli.js index 7f0d3b3e..84325fb7 100755 --- a/server/cli.js +++ b/server/cli.js @@ -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') diff --git a/server/cli/events.js b/server/cli/events.js new file mode 100644 index 00000000..4f6557b2 --- /dev/null +++ b/server/cli/events.js @@ -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 \ No newline at end of file