This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.ts
91 lines (72 loc) · 2.04 KB
/
cli.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { getLogger } from "https://deno.land/[email protected]/log/mod.ts";
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
import { setupLog } from "./log.ts";
import { OpenSSLConfig } from "./openssl.ts";
import { run } from "./mod.ts";
import { getPkg } from "./pkg.ts";
const LOGO = `
_ _ _ _ _____ _____ __
| | | |___| |_| __| __| |
| | | | -_| . |__ |__ | |__
|_____|___|___|_____|_____|_____|
`;
const __HELP = `${LOGO}
Create certificates for local web and mobile development with ease.
USAGE:
$ webssl [options] <destination>
ARGUMENTS:
<destination> Destination folder for all files (required)
Path can be absolute (starting with \`/\` or \`~/\`) or relative. Relative paths
will be resolved with the folder you are executing this script from.
OPTIONS:
--help prints this help message
--debug print some debuggin information
--config path to a custom config toml
--filename the generated files filename
--version print the program version
`;
interface CliArgs {
_: string[];
help: boolean;
debug: boolean;
config: string;
filename: string;
version: boolean;
}
const args = parse(Deno.args) as CliArgs;
const pkg = getPkg();
const debug = typeof args.debug === "boolean" ? args.debug : false;
if (args.help) {
console.log(__HELP);
Deno.exit();
}
if (args.version) {
console.log(pkg.version);
Deno.exit();
}
console.log(LOGO);
await setupLog(debug ? "DEBUG" : "INFO", debug);
const logger = getLogger("cli");
logger.info("Starting...");
logger.debug("Args:\n", JSON.stringify(args, null, 2));
const openSSLConfig: Partial<OpenSSLConfig> = {};
if (args.filename) {
openSSLConfig.filename = args.filename;
}
if (args._.length > 0) {
openSSLConfig.destination = args._[0];
}
try {
await run(openSSLConfig, {
config: args.config,
debug: debug,
});
logger.info("Done!");
} catch (error) {
if (debug) {
logger.error(error);
} else {
logger.error(error.message);
console.log(__HELP);
}
}