add keyout option

This commit is contained in:
monoid 2023-01-06 17:48:51 +09:00
parent b5a1ab29bc
commit 94b624f312

View File

@ -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 <file:string>", "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 ){