1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| const db = require("../lib/db")
| const searchLib = require("../lib/search")
| const yargs = require("yargs")
|
| /////////////////////////////////////////////////////////////////////////
|
| const argv = yargs
| .usage("$0 <search> [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})
| }
|
|