-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
92 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { generateASN } from "$common/asn.ts"; | ||
import z from "@collinhacks/zod"; | ||
|
||
const generateArgs = z.object({ | ||
count: z.number().default(1), | ||
}); | ||
|
||
export async function runGenerate(args: unknown) { | ||
const parsedArgs = generateArgs.parse(args); | ||
|
||
new Array(parsedArgs.count).fill(0).map(() => | ||
generateASN({ | ||
client: "cli", | ||
generatedCount: parsedArgs.count, | ||
}).then(asn => asn.asn) | ||
).forEach(async (x) => console.log(await x)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function printHelp() { | ||
const cmd = Deno.args[0]; | ||
console.log(` | ||
Usage: ${cmd} [command] [options] | ||
Commands: | ||
server Start the server (default) | ||
--port <port> Port to listen on (defaults to the PORT environment variable) | ||
--host <host> Hostname to listen on (defaults to localhost) | ||
generate Generate new ASNs | ||
--count <n> Number of ASNs to generate (defaults to 1) | ||
Options: | ||
--help Show this help message | ||
`.trim()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { z } from "@collinhacks/zod"; | ||
import { CONFIG, logPaths } from "$common/mod.ts"; | ||
import { httpApp } from "$http/mod.tsx"; | ||
import metadata from "$/deno.json" with { type: "json" }; | ||
|
||
const serverArgs = z.object({ | ||
port: z.number().default(CONFIG.PORT), | ||
host: z.string().default("localhost"), | ||
}); | ||
|
||
export function runServer(args: unknown) { | ||
console.log(`Running ${metadata.name} v${metadata.version}`); | ||
console.log(); | ||
|
||
const parsedArgs = serverArgs.parse(args); | ||
|
||
console.log(`Starting server on ${parsedArgs.host}:${parsedArgs.port}`); | ||
|
||
console.log("Environment Configuration:", CONFIG); | ||
console.log("Arguments:", parsedArgs); | ||
console.log("Paths:"); | ||
logPaths(); | ||
|
||
console.log(); | ||
Deno.serve( | ||
{ port: parsedArgs.port, hostname: parsedArgs.host }, | ||
httpApp.fetch, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import { getFormatDescription } from "./lib/common/asn.ts"; | ||
import { CONFIG, logPaths, validateDB } from "$common/mod.ts"; | ||
import { httpApp } from "./lib/http/mod.tsx"; | ||
import metadata from "./deno.json" with { type: "json" }; | ||
import { parseArgs } from "@std/cli/parse-args"; | ||
import { validateDB } from "$common/mod.ts"; | ||
|
||
if (import.meta.main) { | ||
console.log(`Running ${metadata.name} v${metadata.version}`); | ||
console.log(); | ||
|
||
logPaths(); | ||
|
||
console.log(); | ||
import { runServer } from "$cli/server.ts"; | ||
import { printHelp } from "$cli/help.ts"; | ||
import { runGenerate } from "$cli/generate.ts"; | ||
|
||
if (import.meta.main) { | ||
await validateDB(); | ||
console.log(getFormatDescription()); | ||
const args = parseArgs(Deno.args); | ||
|
||
if (args.help) { | ||
printHelp(); | ||
Deno.exit(); | ||
} | ||
|
||
console.log(); | ||
if (args._[0] === "generate") { | ||
await runGenerate(args); | ||
} | ||
|
||
Deno.serve({ port: CONFIG.PORT }, httpApp.fetch); | ||
if (args._[0] === "server" || args._.length === 0) { | ||
await runServer(args); | ||
} | ||
} |