diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-06-13 17:43:10 +0800 | 
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-06-13 17:43:10 +0800 | 
| commit | 4083cac63ee12deb6c32664031209de367a64b29 (patch) | |
| tree | 989e6bc3e253ea54973104209290fd6bce3ee8be /deno/tools | |
| parent | 87e041cd350b76cdfb9bb440e31c25e0d58ab6fb (diff) | |
| download | crupest-4083cac63ee12deb6c32664031209de367a64b29.tar.gz crupest-4083cac63ee12deb6c32664031209de367a64b29.tar.bz2 crupest-4083cac63ee12deb6c32664031209de367a64b29.zip  | |
deno: use yargs in manage-service.
Diffstat (limited to 'deno/tools')
| -rw-r--r-- | deno/tools/manage-service.ts | 73 | 
1 files changed, 38 insertions, 35 deletions
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();  }  | 
