summaryrefslogtreecommitdiff
path: root/core/gjs
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-09-01 19:11:41 +0000
committerAylur <[email protected]>2024-09-01 19:11:41 +0000
commit9be159f873bb58851772f278255913c4fd6e7c0d (patch)
tree39423e4e182c0ddf1adecddcf60b59c4151c20d4 /core/gjs
parent6c4753b5e14a50c617e326d97d270ff51156a183 (diff)
docs: utilities
Diffstat (limited to 'core/gjs')
-rw-r--r--core/gjs/src/process.ts25
1 files changed, 12 insertions, 13 deletions
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<Out = void, Err = void> = {
+type Args = {
cmd: string | string[]
- out?: (stdout: string) => Out
- err?: (stderr: string) => Err
-}
-
-function args<O, E>(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)