Troopa status, response
This commit is contained in:
1 file changed
+21
-9
+21
-9
@@ -51,23 +51,32 @@ export class Troopa implements PromiseLike<Deno.CommandOutput> {
|
|||||||
get stdout() { return this.process.stdout }
|
get stdout() { return this.process.stdout }
|
||||||
get stderr() { return this.process.stderr }
|
get stderr() { return this.process.stderr }
|
||||||
|
|
||||||
pipe(into: Troopa): Troopa
|
response(src: 'stdout' | 'stderr' = 'stdout') {
|
||||||
pipe(into: WritableStream): null
|
const source = this.process[src]
|
||||||
pipe(into: Troopa | WritableStream<Uint8Array>): Troopa | null {
|
return new Response(source)
|
||||||
|
}
|
||||||
|
|
||||||
|
async code() {
|
||||||
|
return (await this).code
|
||||||
|
}
|
||||||
|
|
||||||
|
pipe(into: Troopa): typeof into
|
||||||
|
pipe(into: WritableStream): typeof this
|
||||||
|
pipe(into: Troopa | WritableStream<Uint8Array>): Troopa {
|
||||||
if (into instanceof Troopa) {
|
if (into instanceof Troopa) {
|
||||||
this.process.stdout.pipeTo(into.process.stdin)
|
this.process.stdout.pipeTo(into.process.stdin)
|
||||||
return into
|
return into
|
||||||
}
|
}
|
||||||
|
|
||||||
this.process.stdout.pipeTo(into)
|
this.process.stdout.pipeTo(into)
|
||||||
return null
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
then<Resolved = Deno.CommandOutput, Rejected = never>(
|
then<Resolved = Deno.CommandStatus, Rejected = never>(
|
||||||
onfulfilled?: ((a: Deno.CommandOutput) => Resolved | PromiseLike<Resolved>),
|
onfulfilled?: ((a: Deno.CommandStatus) => Resolved | PromiseLike<Resolved>),
|
||||||
onrejected?: ((a: unknown) => Rejected | PromiseLike<Rejected>)
|
onrejected?: ((a: unknown) => Rejected | PromiseLike<Rejected>)
|
||||||
): PromiseLike<Resolved | Rejected> {
|
): PromiseLike<Resolved | Rejected> {
|
||||||
return this.process.output().then(onfulfilled, onrejected)
|
return this.process.status.then(onfulfilled, onrejected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +120,9 @@ if (import.meta.main) {
|
|||||||
const $ = koopa({
|
const $ = koopa({
|
||||||
prefix: 'set -euox pipefail',
|
prefix: 'set -euox pipefail',
|
||||||
})
|
})
|
||||||
$`echo 1; sleep 1; echo 2; sleep 1; echo 3;`
|
const stdout = Deno.stdout.writable
|
||||||
.pipe(Deno.stdout.writable)
|
const x = await $`echo 1; sleep 1; echo 2; sleep 1; echo 3;`
|
||||||
|
.pipe(stdout)
|
||||||
|
|
||||||
|
console.log(`Exit Status: ${x.code}`)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user