diff --git a/keyout.ts b/keyout.ts index d41403c..93b6281 100644 --- a/keyout.ts +++ b/keyout.ts @@ -5,10 +5,21 @@ import { prepareSecretKey } from "./util/secret.ts"; export const key_out_cmd = new Command(); key_out_cmd.name("keyout") .description("Output the secret key.") -.action(async () => { +.option("-f, --file ", "The file to output the key to. (default: stdout)") +.option("--dotenv", "Output the key in dotenv format.") +.action(async ({file, dotenv}) => { const key = await prepareSecretKey(); - const out = await crypto.subtle.exportKey("jwk", key); - console.log(JSON.stringify(out)); + const keyout = await crypto.subtle.exportKey("jwk", key); + let out = JSON.stringify(keyout); + if (dotenv){ + out = [`SECRET_KEY='${out}'`].join("\n"); + } + + if (file){ + await Deno.writeTextFile(file, out); + } else { + console.log(out); + } }); if ( import.meta.main ){