From 7c315503399bf3584526251901eadc87a1a13d32 Mon Sep 17 00:00:00 2001 From: Eric Doughty-Papassideris Date: Tue, 26 Mar 2024 12:06:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Improve=20CLI=20output=20message?= =?UTF-8?q?s=20(#438)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../node/src/cli/cmds/search_cmds/index_all.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts b/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts index e3fa0ef8..cf1cfdc3 100644 --- a/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts +++ b/tdrive/backend/node/src/cli/cmds/search_cmds/index_all.ts @@ -12,6 +12,7 @@ import CompanyUser, { TYPE as CompanyUserTYPE } from "../../../services/user/ent import gr from "../../../services/global-resolver"; type Options = { + spinner: ora.Ora; repository?: string; repairEntities?: boolean; }; @@ -25,7 +26,7 @@ class SearchIndexAll { this.search = this.platform.getProvider("search"); } - public async run(options: Options = {}): Promise { + public async run(options: Options): Promise { const repositories: Map> = new Map(); repositories.set("users", await this.database.getRepository(UserTYPE, User)); @@ -39,7 +40,7 @@ class SearchIndexAll { // Complete user with companies in cache if (options.repository === "users" && options.repairEntities) { - console.log("Complete user with companies in cache"); + options.spinner.info("Complete user with companies in cache"); const companiesUsersRepository = await this.database.getRepository( CompanyUserTYPE, CompanyUser, @@ -67,23 +68,23 @@ class SearchIndexAll { } while (page.page_token); } - console.log("Start indexing..."); + options.spinner.start("Start indexing..."); let count = 0; // Get all items let page: Pagination = { limitStr: "100" }; do { - console.log("Indexed " + count + " items..."); const list = await repository.find({}, { pagination: page }, undefined); page = list.nextPage as Pagination; await this.search.upsert(list.getEntities()); count += list.getEntities().length; + options.spinner.start("Indexed " + count + " items..."); await new Promise(r => setTimeout(r, 200)); } while (page.page_token); - console.log("Emptying flush (10s)..."); + options.spinner.succeed(`${count} items indexed`); + options.spinner.start("Emptying flush (10s)..."); await new Promise(r => setTimeout(r, 10000)); - - console.log("Done!"); + options.spinner.succeed("Done!"); } } @@ -128,6 +129,7 @@ const command: yargs.CommandModule = { // Let this run even without a repository as its error message includes valid repository names await migrator.run({ repository, + spinner, }); spinner.stop();