Skip to content

Commit

Permalink
fix(flags, command): single dash not supported in arguments (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Oct 18, 2020
1 parent 1e579b2 commit 5b30372
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions command/test/command/arguments_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ function cmd() {
.arguments("[foo:string] [bar:number] [baz:boolean] [color:color]");
}

Deno.test("'-' as argument", async () => {
const { args } = await new Command()
.arguments("<input:string>")
.parse(["-"]);
assertEquals(args, ["-"]);
});

Deno.test("valid command argument types", async () => {
const { args } = await cmd().parse(["abc", "123", "true", "red"]);
assertEquals(args, ["abc", 123, true]);
Expand Down
2 changes: 1 addition & 1 deletion flags/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function normalize(args: string[]) {
} else if (arg === "--") {
inLiteral = true;
normalized.push(arg);
} else if (arg[0] === "-") {
} else if (arg.length > 1 && arg[0] === "-") {
const isLong = arg[1] === "-";

if (arg.includes("=")) {
Expand Down
21 changes: 21 additions & 0 deletions flags/test/option/unknown_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { assertEquals } from "../../../dev_deps.ts";
import { parseFlags } from "../../flags.ts";
import type { IParseOptions } from "../../types.ts";

const options = <IParseOptions> {
flags: [{
name: "flag",
aliases: ["f"],
}],
};

Deno.test("unknown flags", () => {
const { flags, unknown, literal } = parseFlags(
["-f", "foo", "-", "--", "bar"],
options,
);

assertEquals(flags, { flag: true });
assertEquals(unknown, ["foo", "-"]);
assertEquals(literal, ["bar"]);
});

0 comments on commit 5b30372

Please sign in to comment.