Replace Deno.Command calls with runCommand.
This commit is contained in:
		
							parent
							
								
									76505c8c1d
								
							
						
					
					
						commit
						dde7db50b0
					
				| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
import { Command } from "./dependencies.ts";
 | 
			
		||||
import { runAndReturnStdout } from "./utilities.ts";
 | 
			
		||||
import { runAndReturnStdout, runCommand } from "./utilities.ts";
 | 
			
		||||
 | 
			
		||||
async function main(): Promise<void> {
 | 
			
		||||
  const { options } = await new Command()
 | 
			
		||||
| 
						 | 
				
			
			@ -21,11 +21,11 @@ async function main(): Promise<void> {
 | 
			
		|||
 | 
			
		||||
  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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
import { Command } from "./dependencies.ts";
 | 
			
		||||
import { runAndReturnStdout } from "./utilities.ts";
 | 
			
		||||
import { runAndReturnStdout, runCommand } from "./utilities.ts";
 | 
			
		||||
 | 
			
		||||
async function main(): Promise<void> {
 | 
			
		||||
  const { options } = await new Command()
 | 
			
		||||
| 
						 | 
				
			
			@ -27,15 +27,15 @@ async function main(): Promise<void> {
 | 
			
		|||
  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<void> {
 | 
			
		|||
      ...files,
 | 
			
		||||
      "/etc/nixos/",
 | 
			
		||||
    ],
 | 
			
		||||
  }).output();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  if (options.rebuild) {
 | 
			
		||||
    await new Deno.Command("sudo", {
 | 
			
		||||
    await runCommand("sudo", {
 | 
			
		||||
      args: ["nixos-rebuild", options.rebuild],
 | 
			
		||||
    }).output();
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<void> {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
async function downloadImage(url: string): Promise<void> {
 | 
			
		||||
  await new Deno.Command("curl", {
 | 
			
		||||
  await runCommand("curl", {
 | 
			
		||||
    args: ["-fsLS", url, "-o", imagePath],
 | 
			
		||||
  }).output();
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function setWallpaper(file: string = imagePath): Promise<void> {
 | 
			
		||||
  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<void> {
 | 
			
		|||
        "-s",
 | 
			
		||||
        file,
 | 
			
		||||
      ],
 | 
			
		||||
    }).output();
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<void> {
 | 
			
		|||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  await new Deno.Command("youtube3", {
 | 
			
		||||
  await runCommand("youtube3", {
 | 
			
		||||
    args: [
 | 
			
		||||
      "videos",
 | 
			
		||||
      "update",
 | 
			
		||||
| 
						 | 
				
			
			@ -62,7 +62,7 @@ async function main(): Promise<void> {
 | 
			
		|||
      "-r",
 | 
			
		||||
      `snippet.title=${title}`,
 | 
			
		||||
    ],
 | 
			
		||||
  }).output();
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function formatDescription(frontmatter: Frontmatter): string {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
import { Command } from "./dependencies.ts";
 | 
			
		||||
import { pathExists } from "./utilities.ts";
 | 
			
		||||
import { pathExists, runCommand } from "./utilities.ts";
 | 
			
		||||
 | 
			
		||||
async function main(): Promise<void> {
 | 
			
		||||
  const { args, options } = await new Command()
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +30,7 @@ async function main(): Promise<void> {
 | 
			
		|||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  await new Deno.Command("gegl", {
 | 
			
		||||
  await runCommand("gegl", {
 | 
			
		||||
    args: [
 | 
			
		||||
      "-o",
 | 
			
		||||
      file,
 | 
			
		||||
| 
						 | 
				
			
			@ -42,14 +42,14 @@ async function main(): Promise<void> {
 | 
			
		|||
        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<void> {
 | 
			
		|||
      `${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] });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
import { Command } from "./dependencies.ts";
 | 
			
		||||
import { runAndReturnStdout } from "./utilities.ts";
 | 
			
		||||
import { runAndReturnStdout, runCommand } from "./utilities.ts";
 | 
			
		||||
 | 
			
		||||
async function main(): Promise<void> {
 | 
			
		||||
  const { args } = await new Command()
 | 
			
		||||
| 
						 | 
				
			
			@ -24,14 +24,14 @@ async function main(): Promise<void> {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
async function gitPush(remote: string, args: string[]): Promise<void> {
 | 
			
		||||
  await new Deno.Command("git", {
 | 
			
		||||
  await runCommand("git", {
 | 
			
		||||
    args: [
 | 
			
		||||
      "push",
 | 
			
		||||
      "--follow-tags",
 | 
			
		||||
      remote,
 | 
			
		||||
      ...args,
 | 
			
		||||
    ],
 | 
			
		||||
  }).output();
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function gitRemote(): Promise<string[]> {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<Status> {
 | 
			
		|||
 | 
			
		||||
async function notifyCurrentSong(): Promise<void> {
 | 
			
		||||
  const status = await getStatus();
 | 
			
		||||
  await new Deno.Command("notify-send", {
 | 
			
		||||
  await runCommand("notify-send", {
 | 
			
		||||
    args: [status.title, status.artist],
 | 
			
		||||
  }).output();
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (import.meta.main) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<void> {
 | 
			
		||||
  await new Deno.Command(command, options).output();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function runAndReturnStdout(
 | 
			
		||||
  command: string,
 | 
			
		||||
  options: Deno.CommandOptions = {},
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in New Issue