From 687c1ac5e8365b881b02f7db86d10396c3fe4394 Mon Sep 17 00:00:00 2001 From: monoid Date: Fri, 6 Jan 2023 22:57:57 +0900 Subject: [PATCH] add cmd options --- main.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/main.ts b/main.ts index c4d8f09..5147443 100644 --- a/main.ts +++ b/main.ts @@ -25,6 +25,8 @@ import { serve } from "http/server.ts"; import { user_command } from "./user.ts"; import { key_out_cmd } from "./keyout.ts"; import { prepareDocs } from "./src/store/doc.ts"; +import { connectDB } from "./src/user/db.ts"; +import * as users from "./src/user/user.ts"; const github_markdown = (await Deno.readTextFile( join(fromFileUrl(import.meta.url), "..", "static", "github-markdown.css"), @@ -81,12 +83,26 @@ if (import.meta.main) { default: 8000, }) .option("--auth", "Enable authentication.") + .option("--db-path ", "The path to the database file.", { + default: ":memory:", + }) + .option("--id-password ", "The password to use. (Not recommended). id:password format.") .arguments("[hostname:string]") - .action(async ({ debug, port, auth }, hostname) => { + .action(async ({ debug, port, auth, dbPath, idPassword }, hostname) => { hostname ??= "localhost"; if (auth) { Deno.env.set("AUTH_REQUIRED", "true"); } + if (dbPath) { + Deno.env.set("DB_PATH", dbPath); + } + if (idPassword) { + Deno.env.set("AUTH_REQUIRED", "true"); + const db = connectDB(); + const [username, password] = idPassword.split(":"); + const new_user = await users.createUser(username, password); + await users.addUser(db, new_user); + } if (debug) { console.log("Debug mode enabled."); }