From dde7db50b0264e7f87536921de70827fb5626c89 Mon Sep 17 00:00:00 2001 From: Bauke Date: Wed, 7 Jun 2023 15:43:02 +0200 Subject: [PATCH] Replace Deno.Command calls with runCommand. --- .bauke/scripts/codium-extensions.ts | 6 +++--- .bauke/scripts/copy-nixos-config.ts | 14 +++++++------- .bauke/scripts/desktop-wallpaper.ts | 9 +++++---- .bauke/scripts/edit-youtube-video.ts | 6 +++--- .bauke/scripts/project-avatar.ts | 12 ++++++------ .bauke/scripts/simple-git-push.ts | 6 +++--- .bauke/scripts/tauon-controls.ts | 6 +++--- .bauke/scripts/utilities.ts | 10 ++++++++++ 8 files changed, 40 insertions(+), 29 deletions(-) diff --git a/.bauke/scripts/codium-extensions.ts b/.bauke/scripts/codium-extensions.ts index 255be63..1c3d850 100644 --- a/.bauke/scripts/codium-extensions.ts +++ b/.bauke/scripts/codium-extensions.ts @@ -1,5 +1,5 @@ import { Command } from "./dependencies.ts"; -import { runAndReturnStdout } from "./utilities.ts"; +import { runAndReturnStdout, runCommand } from "./utilities.ts"; async function main(): Promise { const { options } = await new Command() @@ -21,11 +21,11 @@ async function main(): Promise { if (options.install) { const extensions = await getSavedExtensions(options.file); - await new Deno.Command("codium", { + await runCommand("codium", { args: [ ...extensions.flatMap((id) => ["--install-extension", id]), ], - }).output(); + }); } if (options.list) { diff --git a/.bauke/scripts/copy-nixos-config.ts b/.bauke/scripts/copy-nixos-config.ts index 042e391..54760b0 100644 --- a/.bauke/scripts/copy-nixos-config.ts +++ b/.bauke/scripts/copy-nixos-config.ts @@ -1,5 +1,5 @@ import { Command } from "./dependencies.ts"; -import { runAndReturnStdout } from "./utilities.ts"; +import { runAndReturnStdout, runCommand } from "./utilities.ts"; async function main(): Promise { const { options } = await new Command() @@ -27,15 +27,15 @@ async function main(): Promise { if (options.diff) { for (const file of files) { const filename = file.slice(file.lastIndexOf("/") + 1); - await new Deno.Command("delta", { + await runCommand("delta", { args: [`/etc/nixos/${filename}`, file], - }).output(); + }); } return; } - await new Deno.Command("sudo", { + await runCommand("sudo", { args: [ "cp", "--preserve=timestamps", @@ -43,12 +43,12 @@ async function main(): Promise { ...files, "/etc/nixos/", ], - }).output(); + }); if (options.rebuild) { - await new Deno.Command("sudo", { + await runCommand("sudo", { args: ["nixos-rebuild", options.rebuild], - }).output(); + }); } } diff --git a/.bauke/scripts/desktop-wallpaper.ts b/.bauke/scripts/desktop-wallpaper.ts index e1552e2..f93b061 100644 --- a/.bauke/scripts/desktop-wallpaper.ts +++ b/.bauke/scripts/desktop-wallpaper.ts @@ -1,4 +1,5 @@ import { Command } from "./dependencies.ts"; +import { runCommand } from "./utilities.ts"; const imagePath = new URL("../data/wallpaper.jpg", import.meta.url).pathname; @@ -41,15 +42,15 @@ async function main(): Promise { } async function downloadImage(url: string): Promise { - await new Deno.Command("curl", { + await runCommand("curl", { args: ["-fsLS", url, "-o", imagePath], - }).output(); + }); } async function setWallpaper(file: string = imagePath): Promise { const monitors = ["monitorHDMI-0", "monitorHDMI-1"]; for (const monitor of monitors) { - await new Deno.Command("xfconf-query", { + await runCommand("xfconf-query", { args: [ "-c", "xfce4-desktop", @@ -58,7 +59,7 @@ async function setWallpaper(file: string = imagePath): Promise { "-s", file, ], - }).output(); + }); } } diff --git a/.bauke/scripts/edit-youtube-video.ts b/.bauke/scripts/edit-youtube-video.ts index cd9d4ad..0a1be38 100644 --- a/.bauke/scripts/edit-youtube-video.ts +++ b/.bauke/scripts/edit-youtube-video.ts @@ -1,5 +1,5 @@ import { Command } from "./dependencies.ts"; -import { tomlFrontmatter } from "./utilities.ts"; +import { runCommand, tomlFrontmatter } from "./utilities.ts"; type Frontmatter = { page_title: string; @@ -49,7 +49,7 @@ async function main(): Promise { return; } - await new Deno.Command("youtube3", { + await runCommand("youtube3", { args: [ "videos", "update", @@ -62,7 +62,7 @@ async function main(): Promise { "-r", `snippet.title=${title}`, ], - }).output(); + }); } function formatDescription(frontmatter: Frontmatter): string { diff --git a/.bauke/scripts/project-avatar.ts b/.bauke/scripts/project-avatar.ts index 480cfba..c8008f0 100644 --- a/.bauke/scripts/project-avatar.ts +++ b/.bauke/scripts/project-avatar.ts @@ -1,5 +1,5 @@ import { Command } from "./dependencies.ts"; -import { pathExists } from "./utilities.ts"; +import { pathExists, runCommand } from "./utilities.ts"; async function main(): Promise { const { args, options } = await new Command() @@ -30,7 +30,7 @@ async function main(): Promise { } } - await new Deno.Command("gegl", { + await runCommand("gegl", { args: [ "-o", file, @@ -42,14 +42,14 @@ async function main(): Promise { width: options.width, }), ], - }).output(); + }); if (!await pathExists(file)) { console.log("Something went wrong with GEGL."); Deno.exit(1); } - await new Deno.Command("convert", { + await runCommand("convert", { args: [ file, "-background", @@ -60,10 +60,10 @@ async function main(): Promise { `${options.width}x${options.height}`, file, ], - }).output(); + }); if (options.clean) { - await new Deno.Command("mat2", { args: ["--inplace", file] }).output(); + await runCommand("mat2", { args: ["--inplace", file] }); } } diff --git a/.bauke/scripts/simple-git-push.ts b/.bauke/scripts/simple-git-push.ts index 6e0e690..9bf84df 100644 --- a/.bauke/scripts/simple-git-push.ts +++ b/.bauke/scripts/simple-git-push.ts @@ -1,5 +1,5 @@ import { Command } from "./dependencies.ts"; -import { runAndReturnStdout } from "./utilities.ts"; +import { runAndReturnStdout, runCommand } from "./utilities.ts"; async function main(): Promise { const { args } = await new Command() @@ -24,14 +24,14 @@ async function main(): Promise { } async function gitPush(remote: string, args: string[]): Promise { - await new Deno.Command("git", { + await runCommand("git", { args: [ "push", "--follow-tags", remote, ...args, ], - }).output(); + }); } async function gitRemote(): Promise { diff --git a/.bauke/scripts/tauon-controls.ts b/.bauke/scripts/tauon-controls.ts index c694e5e..e65a01d 100644 --- a/.bauke/scripts/tauon-controls.ts +++ b/.bauke/scripts/tauon-controls.ts @@ -1,5 +1,5 @@ import { Command } from "./dependencies.ts"; -import { pathExists } from "./utilities.ts"; +import { pathExists, runCommand } from "./utilities.ts"; const hiddenApi = "http://127.0.0.1:7813"; const remoteApi = "http://127.0.0.1:7814/api1"; @@ -96,9 +96,9 @@ async function getStatus(): Promise { async function notifyCurrentSong(): Promise { const status = await getStatus(); - await new Deno.Command("notify-send", { + await runCommand("notify-send", { args: [status.title, status.artist], - }).output(); + }); } if (import.meta.main) { diff --git a/.bauke/scripts/utilities.ts b/.bauke/scripts/utilities.ts index 05fa5eb..856b966 100644 --- a/.bauke/scripts/utilities.ts +++ b/.bauke/scripts/utilities.ts @@ -13,6 +13,16 @@ export function stringifyJsonPretty(input: unknown): string { return JSON.stringify(input, null, 2); } +export async function runCommand( + command: string, + options: Deno.CommandOptions = { + stderr: "inherit", + stdout: "inherit", + }, +): Promise { + await new Deno.Command(command, options).output(); +} + export async function runAndReturnStdout( command: string, options: Deno.CommandOptions = {},