♻️ Improved repository list argument merging for multiple entity types (#438)
This commit is contained in:
committed by
ericlinagora
parent
25ed0c2066
commit
4dae950ac7
@@ -15,6 +15,7 @@ import { EntityTarget, SearchServiceAPI } from "../../../core/platform/services/
|
|||||||
import CompanyUser, { TYPE as CompanyUserTYPE } from "../../../services/user/entities/company_user";
|
import CompanyUser, { TYPE as CompanyUserTYPE } from "../../../services/user/entities/company_user";
|
||||||
import runWithPlatform from "../../lib/run_with_platform";
|
import runWithPlatform from "../../lib/run_with_platform";
|
||||||
import SearchRepository from "src/core/platform/services/search/repository";
|
import SearchRepository from "src/core/platform/services/search/repository";
|
||||||
|
import parseYargsCommaSeparatedStringArray from "../../utils/yargs_comma_array";
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
spinner: ora.Ora;
|
spinner: ora.Ora;
|
||||||
@@ -180,22 +181,12 @@ const command: yargs.CommandModule<unknown, unknown> = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
handler: async argv => {
|
handler: async argv => {
|
||||||
const repositoryArg = argv[repositoryArgumentName];
|
const repositories = parseYargsCommaSeparatedStringArray(
|
||||||
const repositories =
|
argv[repositoryArgumentName] as string /* ignore typechecker */,
|
||||||
typeof repositoryArg === "string" ? [repositoryArg] : (repositoryArg as [string]);
|
);
|
||||||
|
|
||||||
function* eachOnlyOnce<T>(list: Iterable<T>): Iterable<T> {
|
|
||||||
const seen = new Set<T>();
|
|
||||||
for (const item of list) {
|
|
||||||
if (seen.has(item)) continue;
|
|
||||||
seen.add(item);
|
|
||||||
yield item;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
runWithPlatform("Re-index", async ({ spinner, platform }) => {
|
runWithPlatform("Re-index", async ({ spinner, platform }) => {
|
||||||
try {
|
try {
|
||||||
for (const repositoryName of eachOnlyOnce(repositories))
|
for (const repositoryName of repositories)
|
||||||
await RepositoryNameToCTOR.get(repositoryName)(platform, {
|
await RepositoryNameToCTOR.get(repositoryName)(platform, {
|
||||||
spinner,
|
spinner,
|
||||||
repairEntities: !!argv.repairEntities,
|
repairEntities: !!argv.repairEntities,
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import _ from "lodash";
|
||||||
|
|
||||||
|
/** Take potentially repeated string yarg arguments and make into garanteed string array; comma separated and whitespace trimed */
|
||||||
|
export default function parseYargsCommaSeparatedStringArray(
|
||||||
|
args: undefined | string | string[],
|
||||||
|
): string[] {
|
||||||
|
return _.uniq(
|
||||||
|
(typeof args === "string" ? [args] : ((args || []) as string[]))
|
||||||
|
.join(",")
|
||||||
|
.split(",")
|
||||||
|
.map(x => (x || "").trim())
|
||||||
|
.filter(x => x),
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user