Skip to content

Commit

Permalink
[FIX] made error for a bad flag more intelligible
Browse files Browse the repository at this point in the history
[FIX] type for Execute to have arguments (default is Deno.args)
  • Loading branch information
aricart committed Sep 15, 2021
1 parent 2946973 commit 30939e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from "https://deno.land/std/flags/mod.ts";
import { sprintf } from "https://deno.land/std/fmt/printf.ts";
import { parse } from "https://deno.land/std@0.103.0/flags/mod.ts";
import { sprintf } from "https://deno.land/std@0.103.0/fmt/printf.ts";

export interface Flag {
type: "string" | "boolean" | "number";
Expand Down Expand Up @@ -89,7 +89,7 @@ export class FlagsImpl implements Flags {
value<T = unknown>(n: string): T {
const f = this.m.get(n);
if (!f) {
throw new Error(`unknown flag ${n}`);
throw new Error(`unknown flag '${n}'`);
}
let v = f.value ?? f.default ?? this.defaultValue(f);
if (Array.isArray(v)) {
Expand All @@ -101,7 +101,7 @@ export class FlagsImpl implements Flags {
values<T = unknown>(n: string): T[] {
const f = this.m.get(n);
if (!f) {
throw new Error(`unknown flag ${n}`);
throw new Error(`unknown flag '${n}'`);
}
let v = f.value ?? [];
if (!Array.isArray(v)) {
Expand Down Expand Up @@ -320,7 +320,7 @@ export class Command implements Cmd {
}

export interface Execute {
execute(): void;
execute(args: string[]): void;
}

export class RootCommand extends Command implements Execute {
Expand Down
6 changes: 3 additions & 3 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
assertArrayIncludes,
assertEquals,
assertThrows,
} from "https://deno.land/std/testing/asserts.ts";
} from "https://deno.land/std@0.103.0/testing/asserts.ts";
import { cli, Cmd, Command, Flags } from "./mod.ts";

export function buildCmd(v: Partial<Cmd>, debug = false): Cmd {
Expand Down Expand Up @@ -154,7 +154,7 @@ Deno.test("flags - unknown flag throws", async () => {
flags.value<boolean>("bad");
},
Error,
"unknown flag bad",
"unknown flag 'bad'",
);

return Promise.resolve(0);
Expand Down Expand Up @@ -251,7 +251,7 @@ Deno.test("flags - unknown values throws", async () => {
flags.values<boolean>("bad");
},
Error,
"unknown flag bad",
"unknown flag 'bad'",
);

return Promise.resolve(0);
Expand Down

0 comments on commit 30939e3

Please sign in to comment.