ya-webadb/libraries/android-bin/src/utils.ts
2023-09-21 17:01:46 +08:00

29 lines
887 B
TypeScript

export function buildArguments<T>(
commands: string[],
options: Partial<T> | undefined,
map: Partial<Record<keyof T, string>>,
): string[] {
const args = commands;
if (options) {
for (const [key, value] of Object.entries(options)) {
if (value) {
const option = map[key as keyof T];
if (option) {
args.push(option);
switch (typeof value) {
case "number":
args.push(value.toString());
break;
case "string":
args.push(value);
break;
}
}
}
}
}
return args;
}
export type SingleUser = number | "current";
export type SingleUserOrAll = SingleUser | "all";