summaryrefslogtreecommitdiff
path: root/u/process
diff options
context:
space:
mode:
Diffstat (limited to 'u/process')
-rw-r--r--u/process/env.ts15
-rw-r--r--u/process/run.ts33
2 files changed, 32 insertions, 16 deletions
diff --git a/u/process/env.ts b/u/process/env.ts
index 26e1158..65f4e63 100644
--- a/u/process/env.ts
+++ b/u/process/env.ts
@@ -10,3 +10,18 @@ export const getRequiredEnv = (name: string): IEither<Error, string> =>
new Error(`environment variable "${name}" is required D:`),
)
);
+
+export const getRequiredEnvVars = (vars: Array<string>) =>
+ vars
+ .map((envVar) =>
+ [envVar, getRequiredEnv(envVar)] as [string, IEither<Error, string>]
+ )
+ .reduce((acc, x: [string, IEither<Error, string>]) => {
+ const [envVar, eitherVal] = x;
+ return acc.flatMap((args) => {
+ return eitherVal.mapRight((envValue) => ({
+ ...args,
+ [envVar]: envValue,
+ }));
+ });
+ }, Either.right<Error, Record<string, string>>({}));
diff --git a/u/process/run.ts b/u/process/run.ts
index cbf8c65..4954438 100644
--- a/u/process/run.ts
+++ b/u/process/run.ts
@@ -6,21 +6,21 @@ import {
TraceUtil,
} from "@emprespresso/pengueno";
-type Command = string[] | string;
+export type Command = string[] | string;
type CommandOutputDecoded = {
code: number;
stdoutText: string;
stderrText: string;
};
-export class ProcessError extends Error {}
export const getStdout = <Trace>(
c: ITraceable<Command, Trace>,
options: Deno.CommandOptions = {},
-): Promise<IEither<ProcessError, string>> =>
+): Promise<IEither<Error, string>> =>
c.bimap(TraceUtil.withFunctionTrace(getStdout))
- .map(({ item: cmd, trace }) => {
- trace.trace(`:> im gonna run this command! ${cmd}`);
+ .map((tCmd) => {
+ const cmd = tCmd.get();
+ tCmd.trace.trace(`:> im gonna run this command! ${cmd}`);
const [exec, ...args] = (typeof cmd === "string") ? cmd.split(" ") : cmd;
return new Deno.Command(exec, {
args,
@@ -29,12 +29,12 @@ export const getStdout = <Trace>(
...options,
}).output();
})
- .map(({ item: p }) =>
- Either.fromFailableAsync<Error, Deno.CommandOutput>(p)
+ .map((tOut) =>
+ Either.fromFailableAsync<Error, Deno.CommandOutput>(tOut.get())
)
.map(
- TraceUtil.promiseify(({ item: eitherOutput, trace }) =>
- eitherOutput.flatMap(({ code, stderr, stdout }) =>
+ TraceUtil.promiseify((tEitherOut) =>
+ tEitherOut.get().flatMap(({ code, stderr, stdout }) =>
Either
.fromFailable<Error, CommandOutputDecoded>(() => {
const stdoutText = new TextDecoder().decode(stdout);
@@ -42,22 +42,23 @@ export const getStdout = <Trace>(
return { code, stdoutText, stderrText };
})
.mapLeft((e) => {
- trace.addTrace(LogLevel.ERROR).trace(`o.o wat ${e}`);
- return new ProcessError(`${e}`);
+ tEitherOut.trace.addTrace(LogLevel.ERROR).trace(`o.o wat ${e}`);
+ return new Error(`${e}`);
})
- .flatMap((decodedOutput): Either<ProcessError, string> => {
+ .flatMap((decodedOutput): Either<Error, string> => {
const { code, stdoutText, stderrText } = decodedOutput;
- trace.addTrace(LogLevel.DEBUG).trace(
+ tEitherOut.trace.addTrace(LogLevel.DEBUG).trace(
`stderr hehehe ${stderrText}`,
);
if (code !== 0) {
const msg =
`i weceived an exit code of ${code} i wanna zewoooo :<`;
- trace.addTrace(LogLevel.ERROR).trace(msg);
- return Either.left(new ProcessError(msg));
+ tEitherOut.trace.addTrace(LogLevel.ERROR).trace(msg);
+ return Either.left(new Error(msg));
}
return Either.right(stdoutText);
})
)
),
- ).item;
+ )
+ .get();