1
0
Fork 0

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