mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-04 18:29:23 +02:00
feat(adb): subprocess API v3 (#786)
This commit is contained in:
parent
927d50682d
commit
3a6fd9ca08
33 changed files with 979 additions and 580 deletions
|
@ -1,3 +1,5 @@
|
|||
import { escapeArg } from "@yume-chan/adb";
|
||||
|
||||
export function buildArguments<T>(
|
||||
commands: readonly string[],
|
||||
options: Partial<T> | undefined,
|
||||
|
@ -6,19 +8,34 @@ export function buildArguments<T>(
|
|||
const args = commands.slice();
|
||||
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;
|
||||
if (value === undefined || value === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const option = map[key as keyof T];
|
||||
// Empty string means positional argument,
|
||||
// they must be added at the end,
|
||||
// so let the caller handle it.
|
||||
if (option === undefined || option === "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (typeof value) {
|
||||
case "boolean":
|
||||
if (value) {
|
||||
args.push(option);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "number":
|
||||
args.push(option, value.toString());
|
||||
break;
|
||||
case "string":
|
||||
args.push(option, escapeArg(value));
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unsupported type for option ${key}: ${typeof value}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,3 +44,5 @@ export function buildArguments<T>(
|
|||
|
||||
export type SingleUser = number | "current";
|
||||
export type SingleUserOrAll = SingleUser | "all";
|
||||
|
||||
export type Optional<T extends object> = { [K in keyof T]?: T[K] | undefined };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue