aboutsummaryrefslogtreecommitdiff
path: root/packages/web-util/src/cli.ts
blob: 05a22bc8aa7fe2851d4821ed89aba194c8f7d778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { setGlobalLogLevelFromString } from "@gnu-taler/taler-util";
import { clk } from "@gnu-taler/taler-util/clk";
import { serve } from "./serve.js";

export const walletCli = clk
  .program("wallet", {
    help: "Command line interface for the GNU Taler wallet.",
  })
  .maybeOption("log", ["-L", "--log"], clk.STRING, {
    help: "configure log level (NONE, ..., TRACE)",
    onPresentHandler: (x) => {
      setGlobalLogLevelFromString(x);
    },
  })
  .flag("version", ["-v", "--version"], {
    onPresentHandler: printVersion,
  })
  .flag("verbose", ["-V", "--verbose"], {
    help: "Enable verbose output.",
  });

walletCli
  .subcommand("serve", "serve", { help: "Create a server." })
  .maybeOption("folder", ["-F", "--folder"], clk.STRING, {
    help: "should complete",
    // default: "./dist"
  })
  .maybeOption("port", ["-P", "--port"], clk.INT, {
    help: "should complete",
    // default: 8000
  })
  .flag("development", ["-D", "--dev"], {
    help: "should complete",
  })
  .action(async (args) => {
    return serve({
      folder: args.serve.folder || "./dist",
      port: args.serve.port || 8000,
    });
  });

declare const __VERSION__: string;
function printVersion(): void {
  console.log(__VERSION__);
  process.exit(0);
}

export function main(): void {
  walletCli.run();
}