Skip to content

Commit

Permalink
commands: use run instead of commands by default in dance.run
Browse files Browse the repository at this point in the history
  • Loading branch information
71 committed Oct 15, 2021
1 parent 1625ca7 commit 6c63542
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/api/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ export namespace run {
canRunArbitraryCode = false;
}

/**
* Returns whether `compileFunction` and `run` can be used.
*/
export function isEnabled() {
return canRunArbitraryCode;
}

interface CompiledFunction {
(...args: any[]): Thenable<unknown>;
}
Expand Down
16 changes: 10 additions & 6 deletions src/commands/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/commands/load-all.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/commands/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ const runHistory: string[] = [];
* },
* },
* ```
*
* If both `input` and `commands` are given, Dance will use `run` if arbitrary
* command execution is enabled, or `commands` otherwise.
*/
export async function run(
_: Context,
input: string,
inputOr: InputOr<string | readonly string[]>,

count: number,
Expand All @@ -143,7 +147,11 @@ export async function run(
commands?: Argument<command.Any[]>,
) {
if (Array.isArray(commands)) {
return apiCommands(...commands);
if (typeof input === "string" && apiRun.isEnabled()) {
// Prefer "input" to the "commands" array.
} else {
return apiCommands(...commands);
}
}

let code = await inputOr(() => prompt({
Expand Down

0 comments on commit 6c63542

Please sign in to comment.