const db = require("../lib/db") const searchLib = require("../lib/search") const yargs = require("yargs") ///////////////////////////////////////////////////////////////////////// const argv = yargs .usage("$0 [offset] [limit]", "search users",) .option("ids-only", { describe: "only print matching usr_ids", type: "boolean", default: false, }) .strict() .parse() run(argv) .then(print) .catch(console.error) .finally(process.exit) async function run({search, offset, limit, idsOnly}) { if (idsOnly) { return await searchLib.search(String(search)) } offset = offset || 0 limit = limit || 20 return await db.getUsers(offset, limit, String(search)) } function print (res) { if (Array.isArray(res)) { console.log(res) return } const {total, offset, limit, data} = res console.log({data, count: data.length, total, offset, limit}) }