-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(BREAKING): command pipe writes may now return a promise (#225)
- Loading branch information
Showing
18 changed files
with
247 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import { CommandContext } from "../command_handler.ts"; | ||
import { ExecuteResult } from "../result.ts"; | ||
|
||
export function echoCommand(context: CommandContext): ExecuteResult { | ||
context.stdout.writeLine(context.args.join(" ")); | ||
return { code: 0 }; | ||
export function echoCommand(context: CommandContext): ExecuteResult | Promise<ExecuteResult> { | ||
try { | ||
const maybePromise = context.stdout.writeLine(context.args.join(" ")); | ||
if (maybePromise instanceof Promise) { | ||
return maybePromise.then(() => ({ code: 0 })).catch((err) => handleFailure(context, err)); | ||
} else { | ||
return { code: 0 }; | ||
} | ||
} catch (err) { | ||
return handleFailure(context, err); | ||
} | ||
} | ||
|
||
function handleFailure(context: CommandContext, err: any) { | ||
return context.error(`echo: ${err?.message ?? err}`); | ||
} |
Oops, something went wrong.