parseArgs coerced positionals such as 3e21 or 0123 into numbers, so targeting those addresses failed or hit the wrong site.
- commit
- f32cca8e2663e3a5744f5c2d09a56dfa11b2bbc1
- parent
- ef5adede43b47c13771880d255fd49014ca1aab3
- author
- Dami <dami.etoile@gmail.com>
| A | cli/ | 54 | ++++++++++++++++++++++++++++++ |
| M | cli/ | 48 | +-------------------------- |
| M | cli/ | 8 | ++++ |
@@ -0,0 +1,54 @@
1+import { parseArgs } from "@std/cli/parse-args";2+3+/**4+ * Parse CLI arguments. Positionals stay strings: hex addresses such as `3e21` or `0123` would5+ * otherwise be coerced to numbers.6+ */7+export function parseCliArgs(argv: string[]) {8+ return parseArgs(argv, {9+ string: [10+ "_",11+ "ttl",12+ "to",13+ "slot",14+ "server",15+ "token",16+ "password",17+ "name",18+ "description",19+ "default-ttl",20+ "default-for",21+ "framework",22+ "output",23+ "build-task",24+ "title",25+ "open",26+ "tag",27+ "root",28+ "max-ttl",29+ "default-password-file",30+ "message",31+ ],32+ boolean: [33+ "yes",34+ "list",35+ "help",36+ "version",37+ "no-password",38+ "overwrite",39+ "json",40+ "no-description",41+ "all",42+ "no-default-for",43+ "new",44+ "require-password",45+ "allow-unprotected",46+ "no-default-password",47+ "feedback",48+ "no-feedback",49+ "request",50+ ],51+ alias: { h: "help", V: "version", y: "yes" },52+ collect: ["root"],53+ });54+}@@ -16,7 +16,6 @@
1616 */1717 // nzip — push HTML and get a tiny URL back.1818 19-import { parseArgs } from "@std/cli/parse-args";2019 import { VERSION } from "@nzip/shared";2120 import { cmdAuth } from "./commands/auth.ts";2221 import { cmdApp } from "./commands/app.ts";@@ -25,6 +24,7 @@ import { cmdSiteGroup } from "./commands/site.ts";
2524 import { cmdStatus } from "./commands/sites.ts";2625 import { cmdVault } from "./commands/vault.ts";2726 import { requireConfig } from "./lib/config.ts";27+import { parseCliArgs } from "./lib/args.ts";2828 import { fail, setJsonMode } from "./lib/fmt.ts";2929 3030 const HELP = `nzip — html share tool@@ -91,51 +91,7 @@ passwords, tokens, private URLs, or sensitive personal data.
9191 * If configuration, validation, or a command handler fails.9292 */9393 export async function main(argv = Deno.args): Promise<void> {94- const args = parseArgs(argv, {95- string: [96- "ttl",97- "to",98- "slot",99- "server",100- "token",101- "password",102- "name",103- "description",104- "default-ttl",105- "default-for",106- "framework",107- "output",108- "build-task",109- "title",110- "open",111- "tag",112- "root",113- "max-ttl",114- "default-password-file",115- "message",116- ],117- boolean: [118- "yes",119- "list",120- "help",121- "version",122- "no-password",123- "overwrite",124- "json",125- "no-description",126- "all",127- "no-default-for",128- "new",129- "require-password",130- "allow-unprotected",131- "no-default-password",132- "feedback",133- "no-feedback",134- "request",135- ],136- alias: { h: "help", V: "version", y: "yes" },137- collect: ["root"],138- });94+ const args = parseCliArgs(argv);13995 setJsonMode(args.json);14096 const [command, ...rest] = args._.map(String);14197 @@ -1,5 +1,6 @@
11 import { VERSION } from "@nzip/shared";22 import { main } from "./main.ts";3+import { parseCliArgs } from "./lib/args.ts";34 45 async function captureStdout(argv: string[]): Promise<string[]> {56 const lines: string[] = [];@@ -29,3 +30,10 @@ Deno.test("version supports agent-readable JSON", async () => {
2930 throw new Error(`unexpected version JSON: ${lines[0]}`);3031 }3132 });33+34+Deno.test("hex addresses that look numeric stay strings", () => {35+ const positionals = parseCliArgs(["site", "push", "./page", "3e21", "0123"])._;36+ if (JSON.stringify(positionals) !== JSON.stringify(["site", "push", "./page", "3e21", "0123"])) {37+ throw new Error(`positionals were coerced: ${JSON.stringify(positionals)}`);38+ }39+});