Remove bulk.
This commit is contained in:
parent
df820240a2
commit
89a1257e60
|
@ -2,7 +2,6 @@
|
|||
|
||||
## Scripts
|
||||
|
||||
- [`bulk`]: bulk doer of things.
|
||||
- [`codium-extensions`]: save and install VS Codium extensions using their identifier.
|
||||
- [`copy-nixos-config`]: copies NixOS configuration from `$BAUKE_DIR/nix/<hostname>/` to `/etc/nixos/`.
|
||||
- [`desktop-wallpaper`]: desktop wallpaper changer.
|
||||
|
@ -12,7 +11,6 @@
|
|||
- [`simple-git-push`]: `git push` with extra semantics.
|
||||
- [`tauon-controls`]: remote control CLI for Tauon Music Box.
|
||||
|
||||
[`bulk`]: ./scripts/bulk/bulk.ts
|
||||
[`codium-extensions`]: ./scripts/codium-extensions.ts
|
||||
[`copy-nixos-config`]: ./scripts/copy-nixos-config.ts
|
||||
[`desktop-wallpaper`]: ./scripts/desktop-wallpaper.ts
|
||||
|
@ -45,8 +43,6 @@ const { options } = await new Command()
|
|||
console.log(options.file);
|
||||
```
|
||||
|
||||
* An example of subcommands can be seen in [`bulk`], each command is created like above but added to the main CLI via `.command("name", Command)`.
|
||||
|
||||
[Cliffy]: https://cliffy.io
|
||||
|
||||
## Why `bin/` + `scripts/`
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
deno run \
|
||||
--allow-read \
|
||||
--allow-run \
|
||||
"$BAUKE_DIR/scripts/bulk/bulk.ts" \
|
||||
"$@"
|
|
@ -1,16 +0,0 @@
|
|||
import { Command } from "../dependencies.ts";
|
||||
import { moveCommand } from "./move.ts";
|
||||
import { runCommand } from "./run.ts";
|
||||
|
||||
async function main(): Promise<void> {
|
||||
await new Command()
|
||||
.name("bulk")
|
||||
.description("Bulk doer of things.")
|
||||
.command("move", moveCommand)
|
||||
.command("run", runCommand)
|
||||
.parse(Deno.args);
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
void main();
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
import { Command, prompt } from "../dependencies.ts";
|
||||
|
||||
export const moveCommand = new Command()
|
||||
.name("move")
|
||||
.description("Interactively move a group of files.")
|
||||
.option(
|
||||
"-d, --directory <directory:string>",
|
||||
"Directories to include files from.",
|
||||
{
|
||||
collect: true,
|
||||
},
|
||||
)
|
||||
.action(async ({
|
||||
directory,
|
||||
}) => {
|
||||
await actionHandler({ directories: directory ?? [] });
|
||||
});
|
||||
|
||||
async function actionHandler(
|
||||
options: {
|
||||
directories: string[];
|
||||
},
|
||||
): Promise<void> {
|
||||
for (const directory of options.directories) {
|
||||
for await (const file of Deno.readDir(directory)) {
|
||||
if (!file.isFile) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const filename = file.name;
|
||||
const { destination } = await prompt.prompt([{
|
||||
type: prompt.Input,
|
||||
name: "destination",
|
||||
message: `${filename} Destination:`,
|
||||
}]);
|
||||
|
||||
if (destination === undefined || destination === "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: Move the file.
|
||||
console.log(filename, destination);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,180 +0,0 @@
|
|||
import { Command, prompt } from "../dependencies.ts";
|
||||
|
||||
export const runCommand = new Command()
|
||||
.name("run")
|
||||
.description("Run a command over a group of files and directories.")
|
||||
.option(
|
||||
"-d, --directory <directory:string>",
|
||||
"Directories to include files from.",
|
||||
{
|
||||
collect: true,
|
||||
required: true,
|
||||
},
|
||||
)
|
||||
.option(
|
||||
"--include-directories",
|
||||
"Include directories found inside the directories.",
|
||||
)
|
||||
.option(
|
||||
"--output-script",
|
||||
"Output the commands as a shell script instead of running them.",
|
||||
)
|
||||
.action(async ({ directory, includeDirectories, outputScript }) => {
|
||||
await actionHandler({
|
||||
directories: directory,
|
||||
includeDirectories: includeDirectories ?? false,
|
||||
outputScript: outputScript ?? false,
|
||||
});
|
||||
});
|
||||
|
||||
async function actionHandler(
|
||||
options: {
|
||||
directories: string[];
|
||||
includeDirectories: boolean;
|
||||
outputScript: boolean;
|
||||
},
|
||||
): Promise<void> {
|
||||
let command: string[] = [];
|
||||
const previousPromptArgs: Map<number, string> = new Map();
|
||||
const suggestedPromptArgs: Set<string> = new Set();
|
||||
const substituteMarkers = {
|
||||
absoluteFile: "$absoluteFile",
|
||||
filename: "$filename",
|
||||
outWithFile: "$outWithFile",
|
||||
};
|
||||
|
||||
for (const directory of options.directories) {
|
||||
console.log(`\n## Input for ${directory}`);
|
||||
const constructedCommands: string[][] = [];
|
||||
const prompts = await prompt.prompt([
|
||||
{
|
||||
type: prompt.List,
|
||||
name: "command",
|
||||
message: "Arguments of the command to run separated by comma",
|
||||
default: command,
|
||||
suggestions: Object.values(substituteMarkers),
|
||||
},
|
||||
{
|
||||
type: prompt.Confirm,
|
||||
name: "confirmCommands",
|
||||
message: "Manually approve each command invocation",
|
||||
default: true,
|
||||
},
|
||||
]);
|
||||
|
||||
command = prompts.command ?? command;
|
||||
for await (const file of Deno.readDir(directory)) {
|
||||
if (!options.includeDirectories && file.isDirectory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const absoluteFile = await Deno.realPath(`${directory}/${file.name}`);
|
||||
const constructedCommand: string[] = [];
|
||||
let promptArgCount = 1;
|
||||
const substitutes = [
|
||||
[substituteMarkers.absoluteFile, absoluteFile],
|
||||
[substituteMarkers.filename, file.name],
|
||||
[substituteMarkers.outWithFile, `$out/${file.name}`],
|
||||
];
|
||||
|
||||
argumentLoop:
|
||||
for (const argument of command) {
|
||||
if (argument === "$prompt") {
|
||||
const { promptedArg } = await prompt.prompt([{
|
||||
type: prompt.Input,
|
||||
name: "promptedArg",
|
||||
message: `$prompt ${promptArgCount} for ${absoluteFile}`,
|
||||
default: previousPromptArgs.get(promptArgCount) ?? "",
|
||||
suggestions: Array.from(suggestedPromptArgs),
|
||||
}]);
|
||||
|
||||
previousPromptArgs.set(promptArgCount, promptedArg!);
|
||||
suggestedPromptArgs.add(promptedArg!);
|
||||
constructedCommand.push(promptedArg!);
|
||||
promptArgCount += 1;
|
||||
} else {
|
||||
for (const [marker, substitute] of substitutes) {
|
||||
if (argument === marker) {
|
||||
constructedCommand.push(substitute);
|
||||
continue argumentLoop;
|
||||
}
|
||||
}
|
||||
|
||||
constructedCommand.push(argument);
|
||||
}
|
||||
}
|
||||
|
||||
if (prompts.confirmCommands) {
|
||||
const { confirmedRun } = await prompt.prompt([
|
||||
{
|
||||
type: prompt.Confirm,
|
||||
name: "confirmedRun",
|
||||
message: `Run "${constructedCommand.join(" ")}"`,
|
||||
default: true,
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmedRun) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
constructedCommands.push(constructedCommand);
|
||||
}
|
||||
|
||||
if (constructedCommands.length === 0) {
|
||||
console.log("\n No commands to run.");
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log("\n## Commands");
|
||||
console.log(constructedCommands.map((c) => c.join(" ")).join("\n"));
|
||||
|
||||
const { confirmedRun } = await prompt.prompt([
|
||||
{
|
||||
type: prompt.Confirm,
|
||||
name: "confirmedRun",
|
||||
message: "Is this correct",
|
||||
default: true,
|
||||
},
|
||||
]);
|
||||
|
||||
if (!confirmedRun) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (options.outputScript) {
|
||||
const defaultFilename = "bulk-run-script.zsh";
|
||||
const { filename, outputDirectory } = await prompt.prompt([
|
||||
{
|
||||
type: prompt.Input,
|
||||
name: "outputDirectory",
|
||||
message: "Output directory to set as $out",
|
||||
default: ".",
|
||||
},
|
||||
{
|
||||
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
|
||||
|
||||
source "$HOME/.aliases.zsh"
|
||||
out="${outputDirectory}"
|
||||
${commands}`,
|
||||
);
|
||||
} else {
|
||||
console.log("\n## Output");
|
||||
for (const constructedCommand of constructedCommands) {
|
||||
await Deno.run({
|
||||
cmd: constructedCommand,
|
||||
}).status();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue