1
Fork 0

Add a way to output the commands as a script.

This commit is contained in:
Bauke 2023-02-27 12:13:33 +01:00
parent d68d397f66
commit d00d878dc1
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 29 additions and 6 deletions

View File

@ -15,10 +15,15 @@ export const runCommand = new Command()
"--include-directories", "--include-directories",
"Include directories found inside the directories.", "Include directories found inside the directories.",
) )
.action(async ({ directory, includeDirectories }) => { .option(
"--output-script",
"Output the commands as a shell script instead of running them.",
)
.action(async ({ directory, includeDirectories, outputScript }) => {
await actionHandler({ await actionHandler({
directories: directory, directories: directory,
includeDirectories: includeDirectories ?? false, includeDirectories: includeDirectories ?? false,
outputScript: outputScript ?? false,
}); });
}); });
@ -26,6 +31,7 @@ async function actionHandler(
options: { options: {
directories: string[]; directories: string[];
includeDirectories: boolean; includeDirectories: boolean;
outputScript: boolean;
}, },
): Promise<void> { ): Promise<void> {
let command: string[] = []; let command: string[] = [];
@ -135,6 +141,22 @@ async function actionHandler(
continue; continue;
} }
if (options.outputScript) {
const defaultFilename = "bulk-run-script.zsh";
const { filename } = await prompt.prompt([
{
type: prompt.Input,
name: "filename",
message: "Filename for the script",
default: defaultFilename,
},
]);
const commands = constructedCommands.map((c) => c.join(" ")).join("\n");
await Deno.writeTextFile(
filename ?? defaultFilename,
`#!/usr/bin/env zsh\n\n${commands}`,
);
} else {
console.log("\n## Output"); console.log("\n## Output");
for (const constructedCommand of constructedCommands) { for (const constructedCommand of constructedCommands) {
await Deno.run({ await Deno.run({
@ -143,3 +165,4 @@ async function actionHandler(
} }
} }
} }
}