add cli.ts

This commit is contained in:
Michaël Lemaire 2020-11-20 00:00:15 +01:00
parent a6e7906e20
commit 54fd85694d
2 changed files with 23 additions and 14 deletions

7
cli.ts Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env -S deno run --allow-run --allow-read
import { showZenityUI } from "./ui/zenity.ts";
if (import.meta.main) {
// TODO fall back on terminal UI if zenity is not available
await showZenityUI();
}

View file

@ -37,19 +37,21 @@ async function readPrivateKey(): Promise<string> {
return config.privateKey; return config.privateKey;
} }
const privateKey = await readPrivateKey(); export async function showZenityUI(): Promise<void> {
const siteTag = await askInput("site tag:"); const privateKey = await readPrivateKey();
let password = await askInput("password:", true); const siteTag = await askInput("site tag:");
if (password.slice(password.length - 1) != "#") { let password = await askInput("password:", true);
password += "#"; if (password.slice(password.length - 1) != "#") {
} password += "#";
}
const hasher = new Hasher(privateKey); const hasher = new Hasher(privateKey);
hasher.site_tag = siteTag; hasher.site_tag = siteTag;
const result = hasher.tryHashing(password); const result = hasher.tryHashing(password);
if (result) { if (result) {
await copyToClipboard(result); await copyToClipboard(result);
await showMessage(`Your hashed password (copied to clipboard): ${result}`); await showMessage(`Your hashed password (copied to clipboard): ${result}`);
} else { } else {
await showMessage(`Error in hashing password`); await showMessage(`Error in hashing password`);
}
} }