Skip to content

Commit

Permalink
change case of factory functions to match style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
j50n committed Jan 25, 2022
1 parent c4b75b1 commit e79120e
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 215 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ with the group.
`proc` requires that all processes it manages are associated with a `ProcGroup`.

```ts
const pg = procgroup();
const pg = procGroup();
try {
console.log(
await proc(EmptyInput(), StringOutput()).run(pg, {
await proc(emptyInput(), stringOutput()).run(pg, {
cmd: ["ls", "-la"],
}),
);
Expand Down Expand Up @@ -76,12 +76,12 @@ translating for us.
* @return The text compressed into bytes.
*/
async function gzip(text: string): Promise<Uint8Array> {
const pg = procgroup();
const pg = procGroup();
try {
/* I am using a string for input and a Uint8Array (bytes) for output. */
const processDef: Proc<string, Uint8Array> = proc(
StringInput(),
BytesOutput(),
stringInput(),
bytesOutput(),
);

return await processDef.run(pg, {
Expand All @@ -92,7 +92,7 @@ async function gzip(text: string): Promise<Uint8Array> {
}
}

const pg = procgroup();
const pg = procGroup();
try {
console.dir(await gzip("Hello, world."));
} finally {
Expand Down Expand Up @@ -136,10 +136,10 @@ Starting with something simple yet useful, this is an example of running a
`bash` script using `proc`.

```ts
const pg = procgroup();
const pg = procGroup();
try {
console.log(
await proc(EmptyInput(), StringOutput()).run(pg, {
await proc(emptyInput(), stringOutput()).run(pg, {
cmd: [
"/bin/bash",
"--login",
Expand Down
26 changes: 13 additions & 13 deletions proc.readme.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {
BytesOutput,
EmptyInput,
bytesOutput,
emptyInput,
Proc,
proc,
procgroup,
StringInput,
StringOutput,
procGroup,
stringInput,
stringOutput,
} from "./mod.ts";

Deno.test({
name: "[README] Key Concepts | Leaking Resources",
async fn() {
const pg = procgroup();
const pg = procGroup();
try {
console.log(
await proc(EmptyInput(), StringOutput()).run(pg, {
await proc(emptyInput(), stringOutput()).run(pg, {
cmd: ["ls", "-la"],
}),
);
Expand All @@ -33,12 +33,12 @@ Deno.test({
* @return The text compressed into bytes.
*/
async function gzip(text: string): Promise<Uint8Array> {
const pg = procgroup();
const pg = procGroup();
try {
/* I am using a string for input and a Uint8Array (bytes) for output. */
const processDef: Proc<string, Uint8Array> = proc(
StringInput(),
BytesOutput(),
stringInput(),
bytesOutput(),
);

return await processDef.run(pg, {
Expand All @@ -49,7 +49,7 @@ Deno.test({
}
}

const pg = procgroup();
const pg = procGroup();
try {
console.dir(await gzip("Hello, world."));
} finally {
Expand All @@ -61,10 +61,10 @@ Deno.test({
Deno.test({
name: "[README] Examples | Run an Inline Bash Script",
async fn() {
const pg = procgroup();
const pg = procGroup();
try {
console.log(
await proc(EmptyInput(), StringOutput()).run(pg, {
await proc(emptyInput(), stringOutput()).run(pg, {
cmd: [
"/bin/bash",
"--login",
Expand Down
36 changes: 18 additions & 18 deletions proc.types.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { assertEquals, asynciter } from "./deps-test.ts";
import {
EmptyInput,
Proc,
ProcGroup,
StringInput,
StringIterableOutput,
StringOutput,
emptyInput,
proc,
procGroup,
stringInput,
stringIterableOutput,
stringOutput,
} from "./mod.ts";

/**
Expand All @@ -20,10 +20,10 @@ Deno.test({
name:
"[TYPES] When the output is iterable, I get back an AsyncIterator without the Promise wrapper. Input is a string, so I specify the string.",
async fn() {
const proc = new ProcGroup();
const pg = procGroup();
try {
const p1 = new Proc(StringInput(), StringIterableOutput()).run(
proc,
const p1 = proc(stringInput(), stringIterableOutput()).run(
pg,
{
cmd: ["grep", "b"],
},
Expand All @@ -32,7 +32,7 @@ Deno.test({

assertEquals(await asynciter(p1).collect(), ["b", "bb"]);
} finally {
proc.close();
pg.close();
}
},
});
Expand All @@ -41,18 +41,18 @@ Deno.test({
name:
"[TYPES] When the output is iterable, I get back an AsyncIterator without the Promise wrapper. Empty input, so I don't specify input.",
async fn() {
const proc = new ProcGroup();
const pg = procGroup();
try {
const p1 = new Proc(EmptyInput(), StringIterableOutput()).run(
proc,
const p1 = proc(emptyInput(), stringIterableOutput()).run(
pg,
{
cmd: ["bash", "-c", "echo 'Hello.'"],
},
);

assertEquals(await asynciter(p1).collect(), ["Hello."]);
} finally {
proc.close();
pg.close();
}
},
});
Expand All @@ -61,18 +61,18 @@ Deno.test({
name:
"[TYPES] When the output is a string (not iterable), I get back a promise. Empty input so I don't specify input.",
async fn() {
const proc = new ProcGroup();
const pg = procGroup();
try {
const hello = await new Proc(EmptyInput(), StringOutput()).run(
proc,
const hello = await proc(emptyInput(), stringOutput()).run(
pg,
{
cmd: ["bash", "-c", "echo 'Hello.'"],
},
);

assertEquals(hello, "Hello.");
} finally {
proc.close();
pg.close();
}
},
});
4 changes: 2 additions & 2 deletions proc.usage.non-streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ defined, but - aside from `ProcGroup` boilerplate - nothing extra.

```ts
async function gzip(text: string): Promise<Uint8Array> {
const pg = new ProcGroup();
const pg = procGroup();
try {
return await proc(StringInput(), BytesOutput()).run(pg, {
return await proc(stringInput(), bytesOutput()).run(pg, {
cmd: ["gzip", "-c"],
}, text);
} finally {
Expand Down
18 changes: 9 additions & 9 deletions proc.usage.non-streaming.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { assertEquals } from "./deps-test.ts";
import {
BytesInput,
BytesOutput,
bytesInput,
bytesOutput,
proc,
ProcGroup,
StringInput,
StringOutput,
procGroup,
stringInput,
stringOutput,
} from "./mod.ts";
import { randomString } from "./runners/utility.ts";

async function gzip(text: string): Promise<Uint8Array> {
const pg = new ProcGroup();
const pg = procGroup();
try {
return await proc(StringInput(), BytesOutput()).run(pg, {
return await proc(stringInput(), bytesOutput()).run(pg, {
cmd: ["gzip", "-c"],
}, text);
} finally {
Expand All @@ -21,9 +21,9 @@ async function gzip(text: string): Promise<Uint8Array> {
}

async function gunzip(bytes: Uint8Array): Promise<string> {
const pg = new ProcGroup();
const pg = procGroup();
try {
return await proc(BytesInput(), StringOutput()).run(pg, {
return await proc(bytesInput(), stringOutput()).run(pg, {
cmd: ["gzip", "-cd"],
}, bytes);
} finally {
Expand Down
2 changes: 2 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Release Notes

## 0.3.0 _Prerelease_

## 0.2.0 _Prerelease_

There are no breaking API changes in this release.
Expand Down
16 changes: 8 additions & 8 deletions runners/handlers/bytes-iterable.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { assertEquals } from "../../deps-test.ts";
import { ProcGroup } from "../proc-group.ts";
import { BytesIterableInput, BytesIterableOutput } from "./bytes-iterable.ts";
import { EmptyInput } from "./empty.ts";
import { StringOutput } from "./string.ts";
import { bytesIterableInput, bytesIterableOutput } from "./bytes-iterable.ts";
import { emptyInput } from "./empty.ts";
import { stringOutput } from "./string.ts";

Deno.test({
name:
Expand All @@ -15,18 +15,18 @@ Deno.test({
const proc = new ProcGroup();
try {
const out1 = await proc.run(
EmptyInput(),
BytesIterableOutput(),
emptyInput(),
bytesIterableOutput(),
undefined,
{ cmd: ["bash", "-c", "echo 'Hello, world.'"] },
);
const out2 = await proc.run(
BytesIterableInput(),
BytesIterableOutput(),
bytesIterableInput(),
bytesIterableOutput(),
out1,
{ cmd: ["gzip", "-c"] },
);
const out3 = await proc.run(BytesIterableInput(), StringOutput(), out2, {
const out3 = await proc.run(bytesIterableInput(), stringOutput(), out2, {
cmd: ["gzip", "-cd"],
});

Expand Down
4 changes: 2 additions & 2 deletions runners/handlers/bytes-iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { stderrLinesToConsoleError } from "../stderr-support.ts";
import { DEFAULT_BUFFER_SIZE } from "../utility.ts";
import { AbstractBytesOutputHandler } from "./abstract-handlers.ts";

export function BytesIterableInput(
export function bytesIterableInput(
autoflush = true,
): InputHandler<AsyncIterable<Uint8Array>> {
return new BytesIterableInputHandler(autoflush);
}

export function BytesIterableOutput(
export function bytesIterableOutput(
processStderr: (
lines: AsyncIterable<string>,
) => Promise<unknown | string[]> = stderrLinesToConsoleError,
Expand Down
Empty file added runners/handlers/bytes.md
Empty file.
Empty file added runners/handlers/bytes.test.ts
Empty file.
4 changes: 2 additions & 2 deletions runners/handlers/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { stderrLinesToConsoleError } from "../stderr-support.ts";
import { concat } from "../utility.ts";
import { AbstractBytesOutputHandler } from "./abstract-handlers.ts";

export function BytesInput(): InputHandler<Uint8Array> {
export function bytesInput(): InputHandler<Uint8Array> {
return new BytesInputHandler();
}

export function BytesOutput(
export function bytesOutput(
processStderr: (
lines: AsyncIterable<string>,
) => Promise<unknown | string[]> = stderrLinesToConsoleError,
Expand Down
2 changes: 1 addition & 1 deletion runners/handlers/empty.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MultiCloseWriter } from "../closers.ts";
import { InputHandler } from "../proc-group.ts";

export function EmptyInput() {
export function emptyInput() {
return new EmptyInputHandler();
}

Expand Down
12 changes: 6 additions & 6 deletions runners/handlers/reader.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { assertEquals } from "../../deps-test.ts";
import { ClosableStringReader } from "../closers.ts";
import { procgroup } from "../proc-group.ts";
import { ReaderInput } from "./reader.ts";
import { StringOutput } from "./string.ts";
import { procGroup } from "../proc-group.ts";
import { readerInput } from "./reader.ts";
import { stringOutput } from "./string.ts";

Deno.test({
name: "[HAPPY-PATH] I can read stdin from a reader.",
async fn() {
const proc = procgroup();
const proc = procGroup();
try {
const result = await proc.run(
ReaderInput(),
StringOutput(),
readerInput(),
stringOutput(),
new ClosableStringReader("Hello,\nDeno."),
{ cmd: ["grep", "-P", "."] },
);
Expand Down
2 changes: 1 addition & 1 deletion runners/handlers/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MultiCloseWriter } from "../closers.ts";
import { InputHandler } from "../proc-group.ts";
import { pump } from "../utility.ts";

export function ReaderInput(): InputHandler<Deno.Reader & Deno.Closer> {
export function readerInput(): InputHandler<Deno.Reader & Deno.Closer> {
return new ReaderInputHandler();
}

Expand Down
Loading

0 comments on commit e79120e

Please sign in to comment.