add cmd options

This commit is contained in:
monoid 2023-01-06 22:57:57 +09:00
parent 5fc8ba54da
commit 687c1ac5e8
1 changed files with 17 additions and 1 deletions

18
main.ts
View File

@ -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 <path:string>", "The path to the database file.", {
default: ":memory:",
})
.option("--id-password <idpassword:string>", "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.");
}