From 9be159f873bb58851772f278255913c4fd6e7c0d Mon Sep 17 00:00:00 2001 From: Aylur Date: Sun, 1 Sep 2024 19:11:41 +0000 Subject: docs: utilities --- core/gjs/src/process.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'core/gjs/src') diff --git a/core/gjs/src/process.ts b/core/gjs/src/process.ts index c5329e2..bf8ea28 100644 --- a/core/gjs/src/process.ts +++ b/core/gjs/src/process.ts @@ -1,32 +1,31 @@ import { Astal } from "./imports.js" -type Args = { +type Args = { cmd: string | string[] - out?: (stdout: string) => Out - err?: (stderr: string) => Err -} - -function args(argsOrCmd: Args | string | string[], onOut: O, onErr: E) { - const params = Array.isArray(argsOrCmd) || typeof argsOrCmd === "string" - return { - cmd: params ? argsOrCmd : argsOrCmd.cmd, - err: params ? onErr : argsOrCmd.err || onErr, - out: params ? onOut : argsOrCmd.out || onOut, - } + out?: (stdout: string) => void + err?: (stderr: string) => void } export function subprocess(args: Args): Astal.Process + export function subprocess( cmd: string | string[], onOut?: (stdout: string) => void, onErr?: (stderr: string) => void, ): Astal.Process + export function subprocess( argsOrCmd: Args | string | string[], onOut: (stdout: string) => void = print, onErr: (stderr: string) => void = printerr, ) { - const { cmd, err, out } = args(argsOrCmd, onOut, onErr) + const args = Array.isArray(argsOrCmd) || typeof argsOrCmd === "string" + const { cmd, err, out } = { + cmd: args ? argsOrCmd : argsOrCmd.cmd, + err: args ? onErr : argsOrCmd.err || onErr, + out: args ? onOut : argsOrCmd.out || onOut, + } + const proc = Array.isArray(cmd) ? Astal.Process.subprocessv(cmd) : Astal.Process.subprocess(cmd) -- cgit v1.2.3