aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deno/deno.json1
-rw-r--r--deno/deno.lock2
-rw-r--r--deno/mail-relay/deno.json1
-rw-r--r--deno/tools/manage-service.ts73
4 files changed, 40 insertions, 37 deletions
diff --git a/deno/deno.json b/deno/deno.json
index 0c603a0..dbc6cac 100644
--- a/deno/deno.json
+++ b/deno/deno.json
@@ -4,7 +4,6 @@
"compile:mail-relay": "deno task --cwd=mail-relay compile",
},
"imports": {
- "@std/cli": "jsr:@std/cli@^1.0.19",
"@std/collections": "jsr:@std/collections@^1.1.1",
"@std/csv": "jsr:@std/csv@^1.0.6",
"@std/encoding": "jsr:@std/encoding@^1.0.10",
diff --git a/deno/deno.lock b/deno/deno.lock
index 2f3ac13..0d8b4eb 100644
--- a/deno/deno.lock
+++ b/deno/deno.lock
@@ -1301,7 +1301,6 @@
},
"workspace": {
"dependencies": [
- "jsr:@std/cli@^1.0.19",
"jsr:@std/collections@^1.1.1",
"jsr:@std/csv@^1.0.6",
"jsr:@std/dotenv@~0.225.5",
@@ -1317,6 +1316,7 @@
"mail-relay": {
"dependencies": [
"jsr:@db/sqlite@0.12",
+ "jsr:@std/cli@^1.0.19",
"npm:@aws-sdk/client-s3@^3.821.0",
"npm:@aws-sdk/client-sesv2@^3.821.0",
"npm:@hono/zod-validator@0.7",
diff --git a/deno/mail-relay/deno.json b/deno/mail-relay/deno.json
index 9105747..22aae59 100644
--- a/deno/mail-relay/deno.json
+++ b/deno/mail-relay/deno.json
@@ -5,6 +5,7 @@
"compile": "deno compile -o out/crupest-relay -A aws/app.ts"
},
"imports": {
+ "@std/cli": "jsr:@std/cli@^1.0.19",
"@aws-sdk/client-s3": "npm:@aws-sdk/client-s3@^3.821.0",
"@aws-sdk/client-sesv2": "npm:@aws-sdk/client-sesv2@^3.821.0",
"@db/sqlite": "jsr:@db/sqlite@^0.12.0",
diff --git a/deno/tools/manage-service.ts b/deno/tools/manage-service.ts
index 45e09ec..148f55a 100644
--- a/deno/tools/manage-service.ts
+++ b/deno/tools/manage-service.ts
@@ -1,39 +1,42 @@
-import { parseArgs } from "@std/cli";
-import { TemplateDir } from "./template.ts";
import { join } from "@std/path";
+// @ts-types="npm:@types/yargs"
+import yargs from "yargs";
-if (import.meta.main) {
- const args = parseArgs(Deno.args, {
- string: ["project-dir"],
- boolean: ["no-dry-run"],
- });
-
- if (args._.length === 0) {
- throw new Error("You must specify a command.");
- }
-
- const projectDir = args["project-dir"];
- if (projectDir == null) {
- throw new Error("You must specify project-dir.");
- }
-
- const command = String(args._[0]);
+import { TemplateDir } from "./template.ts";
- switch (command) {
- case "gen-tmpl":
- new TemplateDir(
- join(projectDir, "services/templates"),
- ).generateWithVariableFiles(
- [
- join(projectDir, "data/config"),
- join(projectDir, "services/config.template"),
- ],
- args["no-dry-run"] === true
- ? join(projectDir, "services/generated")
- : undefined,
- );
- break;
- default:
- throw new Error(command + " is not a valid command.");
- }
+if (import.meta.main) {
+ await yargs(Deno.args)
+ .scriptName("manage-service")
+ .option("project-dir", {
+ type: "string",
+ })
+ .demandOption("project-dir")
+ .command({
+ command: "gen-tmpl",
+ describe: "generate files for templates",
+ builder: (builder) => {
+ return builder
+ .option("dry-run", {
+ type: "boolean",
+ default: true,
+ })
+ .strict();
+ },
+ handler: (argv) => {
+ const { projectDir, dryRun } = argv;
+ new TemplateDir(
+ join(projectDir, "services/templates"),
+ ).generateWithVariableFiles(
+ [
+ join(projectDir, "data/config"),
+ join(projectDir, "services/config.template"),
+ ],
+ dryRun ? undefined : join(projectDir, "services/generated"),
+ );
+ },
+ })
+ .demandCommand(1, "One command must be specified.")
+ .help()
+ .strict()
+ .parse();
}