New silverbullet command line structure, allowing for sub-commands
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import * as flags from "https://deno.land/std@0.158.0/flags/mod.ts";
|
||||
import * as path from "https://deno.land/std@0.158.0/path/mod.ts";
|
||||
import { HttpServer } from "./http_server.ts";
|
||||
|
||||
const args = flags.parse(Deno.args, {
|
||||
string: ["port", "password", "builtins"],
|
||||
alias: { p: "port" },
|
||||
default: {
|
||||
port: "3000",
|
||||
},
|
||||
});
|
||||
|
||||
if (!args._.length) {
|
||||
console.error(
|
||||
"Usage: silverbullet [--port 3000] [--password mysecretpassword] <path-to-pages>",
|
||||
);
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
const pagesPath = path.resolve(Deno.cwd(), args._[0] as string);
|
||||
const port = +args.port;
|
||||
|
||||
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
|
||||
import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts";
|
||||
|
||||
console.log("Pages folder:", pagesPath);
|
||||
|
||||
const httpServer = new HttpServer({
|
||||
port: port,
|
||||
pagesPath: pagesPath,
|
||||
assetBundle: new AssetBundle(assetBundle as AssetJson),
|
||||
password: args.password,
|
||||
});
|
||||
httpServer.start().catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
import { Command } from "https://deno.land/x/cliffy@v0.25.2/command/command.ts";
|
||||
|
||||
import * as path from "https://deno.land/std@0.158.0/path/mod.ts";
|
||||
import { HttpServer } from "./http_server.ts";
|
||||
import assetBundle from "../dist/asset_bundle.json" assert { type: "json" };
|
||||
import { AssetBundle, AssetJson } from "../plugos/asset_bundle/bundle.ts";
|
||||
|
||||
await new Command()
|
||||
.name("silverbullet")
|
||||
.description("Markdown as a platform")
|
||||
// Main command
|
||||
.arguments("<folder:string>")
|
||||
.option("-p, --port <port:number>", "Port to listen on")
|
||||
.option("--password <password:string>", "Password for basic authentication")
|
||||
.action((options, folder) => {
|
||||
const pagesPath = path.resolve(Deno.cwd(), folder);
|
||||
const port = options.port || 3000;
|
||||
|
||||
console.log("Pages folder:", pagesPath);
|
||||
|
||||
const httpServer = new HttpServer({
|
||||
port: port,
|
||||
pagesPath: pagesPath,
|
||||
assetBundle: new AssetBundle(assetBundle as AssetJson),
|
||||
password: options.password,
|
||||
});
|
||||
httpServer.start().catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
})
|
||||
// Upgrade command
|
||||
.command("upgrade", "Upgrade Silver Bullet")
|
||||
.action(async () => {
|
||||
console.log("Attempting upgrade...");
|
||||
const p = Deno.run({
|
||||
cmd: ["deno", "cache", "--reload", Deno.mainModule],
|
||||
});
|
||||
const exitCode = await p.status();
|
||||
if (exitCode.success) {
|
||||
console.log("Upgrade succeeded");
|
||||
} else {
|
||||
console.error("Upgrade failed");
|
||||
}
|
||||
})
|
||||
.parse(Deno.args);
|
||||
Reference in New Issue
Block a user