diff --git a/tools/getIssue.ts b/tools/getIssue.ts index 706a7d4..df574f5 100644 --- a/tools/getIssue.ts +++ b/tools/getIssue.ts @@ -1,5 +1,6 @@ #! /usr/bin/env deno run --allow-net --allow-env import {Issue} from "./githubType.ts"; +import {parse} from "https://deno.land/std@0.135.0/flags/mod.ts"; /** * get issue from github @@ -25,13 +26,17 @@ export async function getIssues(repo: string, token: string): Promise { if (import.meta.main) { - const arg = Deno.args.length > 0 ? Deno.args[0] : undefined; - const token = arg ?? Deno.env.get("GITHUB_TOKEN"); + const args = parse(Deno.args); + const token = args.token ?? Deno.env.get("GITHUB_TOKEN"); + if(typeof token !== "string"){ + console.error("invalid type: token must be string"); + Deno.exit(1); + } if(!token) { console.error("GITHUB_TOKEN is not set"); Deno.exit(1); } const issues = await getIssues("vi117/scrap-yard", token); issues.sort((a, b) => a.number - b.number); - console.log(issues.map(i => `# (${i.number}) ${i.title}\n${i.body}`).join("\n\n")); + console.log(JSON.stringify(issues,undefined,2)); } \ No newline at end of file