From 54fd85694dba7c7c67e935754c932cab15bf3747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Fri, 20 Nov 2020 00:00:15 +0100 Subject: [PATCH] add cli.ts --- cli.ts | 7 +++++++ ui/zenity.ts | 30 ++++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) create mode 100755 cli.ts diff --git a/cli.ts b/cli.ts new file mode 100755 index 0000000..384b033 --- /dev/null +++ b/cli.ts @@ -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(); +} diff --git a/ui/zenity.ts b/ui/zenity.ts index 414ae9a..bca710f 100644 --- a/ui/zenity.ts +++ b/ui/zenity.ts @@ -37,19 +37,21 @@ async function readPrivateKey(): Promise { 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 { + 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`); + } }