add cmd options
This commit is contained in:
parent
5fc8ba54da
commit
687c1ac5e8
18
main.ts
18
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 <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.");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user