summaryrefslogtreecommitdiff
path: root/flags
diff options
context:
space:
mode:
Diffstat (limited to 'flags')
-rwxr-xr-xflags/all_bool_test.ts4
-rwxr-xr-xflags/bool_test.ts18
-rwxr-xr-xflags/dash_test.ts6
-rwxr-xr-xflags/default_bool_test.ts6
-rwxr-xr-xflags/dotted_test.ts6
-rwxr-xr-xflags/kv_short_test.ts4
-rwxr-xr-xflags/long_test.ts2
-rw-r--r--flags/mod.ts32
-rwxr-xr-xflags/num_test.ts4
-rwxr-xr-xflags/parse_test.ts26
-rwxr-xr-xflags/short_test.ts8
-rwxr-xr-xflags/stop_early_test.ts2
-rwxr-xr-xflags/unknown_test.ts10
-rwxr-xr-xflags/whitespace_test.ts2
14 files changed, 65 insertions, 65 deletions
diff --git a/flags/all_bool_test.ts b/flags/all_bool_test.ts
index 59779c779..22b6bcd2d 100755
--- a/flags/all_bool_test.ts
+++ b/flags/all_bool_test.ts
@@ -4,7 +4,7 @@ import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
// flag boolean true (default all --args to boolean)
-test(function flagBooleanTrue() {
+test(function flagBooleanTrue(): void {
const argv = parse(["moo", "--honk", "cow"], {
boolean: true
});
@@ -18,7 +18,7 @@ test(function flagBooleanTrue() {
});
// flag boolean true only affects double hyphen arguments without equals signs
-test(function flagBooleanTrueOnlyAffectsDoubleDash() {
+test(function flagBooleanTrueOnlyAffectsDoubleDash(): void {
var argv = parse(["moo", "--honk", "cow", "-p", "55", "--tacos=good"], {
boolean: true
});
diff --git a/flags/bool_test.ts b/flags/bool_test.ts
index 820393543..a33e9be0b 100755
--- a/flags/bool_test.ts
+++ b/flags/bool_test.ts
@@ -3,7 +3,7 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function flagBooleanDefaultFalse() {
+test(function flagBooleanDefaultFalse(): void {
const argv = parse(["moo"], {
boolean: ["t", "verbose"],
default: { verbose: false, t: false }
@@ -19,7 +19,7 @@ test(function flagBooleanDefaultFalse() {
assertEquals(typeof argv.t, "boolean");
});
-test(function booleanGroups() {
+test(function booleanGroups(): void {
const argv = parse(["-x", "-z", "one", "two", "three"], {
boolean: ["x", "y", "z"]
});
@@ -36,7 +36,7 @@ test(function booleanGroups() {
assertEquals(typeof argv.z, "boolean");
});
-test(function booleanAndAliasWithChainableApi() {
+test(function booleanAndAliasWithChainableApi(): void {
const aliased = ["-h", "derp"];
const regular = ["--herp", "derp"];
const aliasedArgv = parse(aliased, {
@@ -57,7 +57,7 @@ test(function booleanAndAliasWithChainableApi() {
assertEquals(propertyArgv, expected);
});
-test(function booleanAndAliasWithOptionsHash() {
+test(function booleanAndAliasWithOptionsHash(): void {
const aliased = ["-h", "derp"];
const regular = ["--herp", "derp"];
const opts = {
@@ -75,7 +75,7 @@ test(function booleanAndAliasWithOptionsHash() {
assertEquals(propertyArgv, expected);
});
-test(function booleanAndAliasArrayWithOptionsHash() {
+test(function booleanAndAliasArrayWithOptionsHash(): void {
const aliased = ["-h", "derp"];
const regular = ["--herp", "derp"];
const alt = ["--harp", "derp"];
@@ -97,7 +97,7 @@ test(function booleanAndAliasArrayWithOptionsHash() {
assertEquals(altPropertyArgv, expected);
});
-test(function booleanAndAliasUsingExplicitTrue() {
+test(function booleanAndAliasUsingExplicitTrue(): void {
const aliased = ["-h", "true"];
const regular = ["--herp", "true"];
const opts = {
@@ -118,7 +118,7 @@ test(function booleanAndAliasUsingExplicitTrue() {
// regression, see https://github.com/substack/node-optimist/issues/71
// boolean and --x=true
-test(function booleanAndNonBoolean() {
+test(function booleanAndNonBoolean(): void {
const parsed = parse(["--boool", "--other=true"], {
boolean: "boool"
});
@@ -134,7 +134,7 @@ test(function booleanAndNonBoolean() {
assertEquals(parsed2.other, "false");
});
-test(function booleanParsingTrue() {
+test(function booleanParsingTrue(): void {
const parsed = parse(["--boool=true"], {
default: {
boool: false
@@ -145,7 +145,7 @@ test(function booleanParsingTrue() {
assertEquals(parsed.boool, true);
});
-test(function booleanParsingFalse() {
+test(function booleanParsingFalse(): void {
const parsed = parse(["--boool=false"], {
default: {
boool: true
diff --git a/flags/dash_test.ts b/flags/dash_test.ts
index 7d52e4905..f4901b352 100755
--- a/flags/dash_test.ts
+++ b/flags/dash_test.ts
@@ -3,7 +3,7 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function hyphen() {
+test(function hyphen(): void {
assertEquals(parse(["-n", "-"]), { n: "-", _: [] });
assertEquals(parse(["-"]), { _: ["-"] });
assertEquals(parse(["-f-"]), { f: "-", _: [] });
@@ -11,13 +11,13 @@ test(function hyphen() {
assertEquals(parse(["-s", "-"], { string: "s" }), { s: "-", _: [] });
});
-test(function doubleDash() {
+test(function doubleDash(): void {
assertEquals(parse(["-a", "--", "b"]), { a: true, _: ["b"] });
assertEquals(parse(["--a", "--", "b"]), { a: true, _: ["b"] });
assertEquals(parse(["--a", "--", "b"]), { a: true, _: ["b"] });
});
-test(function moveArgsAfterDoubleDashIntoOwnArray() {
+test(function moveArgsAfterDoubleDashIntoOwnArray(): void {
assertEquals(
parse(["--name", "John", "before", "--", "after"], { "--": true }),
{
diff --git a/flags/default_bool_test.ts b/flags/default_bool_test.ts
index a1a329074..dc953cdc8 100755
--- a/flags/default_bool_test.ts
+++ b/flags/default_bool_test.ts
@@ -3,7 +3,7 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function booleanDefaultTrue() {
+test(function booleanDefaultTrue(): void {
const argv = parse([], {
boolean: "sometrue",
default: { sometrue: true }
@@ -11,7 +11,7 @@ test(function booleanDefaultTrue() {
assertEquals(argv.sometrue, true);
});
-test(function booleanDefaultFalse() {
+test(function booleanDefaultFalse(): void {
const argv = parse([], {
boolean: "somefalse",
default: { somefalse: false }
@@ -19,7 +19,7 @@ test(function booleanDefaultFalse() {
assertEquals(argv.somefalse, false);
});
-test(function booleanDefaultNull() {
+test(function booleanDefaultNull(): void {
const argv = parse([], {
boolean: "maybe",
default: { maybe: null }
diff --git a/flags/dotted_test.ts b/flags/dotted_test.ts
index d5a491815..6a27eb6f7 100755
--- a/flags/dotted_test.ts
+++ b/flags/dotted_test.ts
@@ -3,7 +3,7 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function dottedAlias() {
+test(function dottedAlias(): void {
const argv = parse(["--a.b", "22"], {
default: { "a.b": 11 },
alias: { "a.b": "aa.bb" }
@@ -12,13 +12,13 @@ test(function dottedAlias() {
assertEquals(argv.aa.bb, 22);
});
-test(function dottedDefault() {
+test(function dottedDefault(): void {
const argv = parse("", { default: { "a.b": 11 }, alias: { "a.b": "aa.bb" } });
assertEquals(argv.a.b, 11);
assertEquals(argv.aa.bb, 11);
});
-test(function dottedDefaultWithNoAlias() {
+test(function dottedDefaultWithNoAlias(): void {
const argv = parse("", { default: { "a.b": 11 } });
assertEquals(argv.a.b, 11);
});
diff --git a/flags/kv_short_test.ts b/flags/kv_short_test.ts
index 0cd93df02..271e5c67d 100755
--- a/flags/kv_short_test.ts
+++ b/flags/kv_short_test.ts
@@ -3,12 +3,12 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function short() {
+test(function short(): void {
const argv = parse(["-b=123"]);
assertEquals(argv, { b: 123, _: [] });
});
-test(function multiShort() {
+test(function multiShort(): void {
const argv = parse(["-a=whatever", "-b=robots"]);
assertEquals(argv, { a: "whatever", b: "robots", _: [] });
});
diff --git a/flags/long_test.ts b/flags/long_test.ts
index fb26a4c07..5b14fc630 100755
--- a/flags/long_test.ts
+++ b/flags/long_test.ts
@@ -3,7 +3,7 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function longOpts() {
+test(function longOpts(): void {
assertEquals(parse(["--bool"]), { bool: true, _: [] });
assertEquals(parse(["--pow", "xixxle"]), { pow: "xixxle", _: [] });
assertEquals(parse(["--pow=xixxle"]), { pow: "xixxle", _: [] });
diff --git a/flags/mod.ts b/flags/mod.ts
index 0c0702e8b..433f4eb15 100644
--- a/flags/mod.ts
+++ b/flags/mod.ts
@@ -10,7 +10,7 @@ export interface ArgParsingOptions {
}
const DEFAULT_OPTIONS = {
- unknown: i => i,
+ unknown: (i): unknown => i,
boolean: false,
alias: {},
string: [],
@@ -27,7 +27,7 @@ function isNumber(x: unknown): boolean {
function hasKey(obj, keys): boolean {
let o = obj;
- keys.slice(0, -1).forEach(function(key) {
+ keys.slice(0, -1).forEach(function(key): void {
o = o[key] || {};
});
@@ -38,8 +38,8 @@ function hasKey(obj, keys): boolean {
export function parse(
args,
initialOptions?: ArgParsingOptions
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
): { [key: string]: any } {
- // eslint-disable-line @typescript-eslint/no-explicit-any
const options: ArgParsingOptions = {
...DEFAULT_OPTIONS,
...(initialOptions || {})
@@ -59,17 +59,17 @@ export function parse(
[]
.concat(options["boolean"])
.filter(Boolean)
- .forEach(function(key) {
+ .forEach(function(key): void {
flags.bools[key] = true;
});
}
const aliases = {};
- Object.keys(options.alias).forEach(function(key) {
+ Object.keys(options.alias).forEach(function(key): void {
aliases[key] = [].concat(options.alias[key]);
- aliases[key].forEach(function(x) {
+ aliases[key].forEach(function(x): void {
aliases[x] = [key].concat(
- aliases[key].filter(function(y) {
+ aliases[key].filter(function(y): boolean {
return x !== y;
})
);
@@ -79,7 +79,7 @@ export function parse(
[]
.concat(options.string)
.filter(Boolean)
- .forEach(function(key) {
+ .forEach(function(key): void {
flags.strings[key] = true;
if (aliases[key]) {
flags.strings[aliases[key]] = true;
@@ -101,7 +101,7 @@ export function parse(
function setKey(obj, keys, value): void {
let o = obj;
- keys.slice(0, -1).forEach(function(key) {
+ keys.slice(0, -1).forEach(function(key): void {
if (o[key] === undefined) o[key] = {};
o = o[key];
});
@@ -128,18 +128,18 @@ export function parse(
const value = !flags.strings[key] && isNumber(val) ? Number(val) : val;
setKey(argv, key.split("."), value);
- (aliases[key] || []).forEach(function(x) {
+ (aliases[key] || []).forEach(function(x): void {
setKey(argv, x.split("."), value);
});
}
function aliasIsBoolean(key): boolean {
- return aliases[key].some(function(x) {
+ return aliases[key].some(function(x): boolean {
return flags.bools[x];
});
}
- Object.keys(flags.bools).forEach(function(key) {
+ Object.keys(flags.bools).forEach(function(key): void {
setArg(key, defaults[key] === undefined ? false : defaults[key]);
});
@@ -249,11 +249,11 @@ export function parse(
}
}
- Object.keys(defaults).forEach(function(key) {
+ Object.keys(defaults).forEach(function(key): void {
if (!hasKey(argv, key.split("."))) {
setKey(argv, key.split("."), defaults[key]);
- (aliases[key] || []).forEach(function(x) {
+ (aliases[key] || []).forEach(function(x): void {
setKey(argv, x.split("."), defaults[key]);
});
}
@@ -261,11 +261,11 @@ export function parse(
if (options["--"]) {
argv["--"] = [];
- notFlags.forEach(function(key) {
+ notFlags.forEach(function(key): void {
argv["--"].push(key);
});
} else {
- notFlags.forEach(function(key) {
+ notFlags.forEach(function(key): void {
argv._.push(key);
});
}
diff --git a/flags/num_test.ts b/flags/num_test.ts
index 752e1752f..1123f7ecc 100755
--- a/flags/num_test.ts
+++ b/flags/num_test.ts
@@ -3,7 +3,7 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function nums() {
+test(function nums(): void {
const argv = parse([
"-x",
"1234",
@@ -33,7 +33,7 @@ test(function nums() {
assertEquals(typeof argv._[0], "number");
});
-test(function alreadyNumber() {
+test(function alreadyNumber(): void {
const argv = parse(["-x", 1234, 789]);
assertEquals(argv, { x: 1234, _: [789] });
assertEquals(typeof argv.x, "number");
diff --git a/flags/parse_test.ts b/flags/parse_test.ts
index dbcdb4a86..2e154f78c 100755
--- a/flags/parse_test.ts
+++ b/flags/parse_test.ts
@@ -3,7 +3,7 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function _arseArgs() {
+test(function _arseArgs(): void {
assertEquals(parse(["--no-moo"]), { moo: false, _: [] });
assertEquals(parse(["-v", "a", "-v", "b", "-v", "c"]), {
v: ["a", "b", "c"],
@@ -11,7 +11,7 @@ test(function _arseArgs() {
});
});
-test(function comprehensive() {
+test(function comprehensive(): void {
assertEquals(
parse([
"--name=meowmers",
@@ -48,13 +48,13 @@ test(function comprehensive() {
);
});
-test(function flagBoolean() {
+test(function flagBoolean(): void {
const argv = parse(["-t", "moo"], { boolean: "t" });
assertEquals(argv, { t: true, _: ["moo"] });
assertEquals(typeof argv.t, "boolean");
});
-test(function flagBooleanValue() {
+test(function flagBooleanValue(): void {
const argv = parse(["--verbose", "false", "moo", "-t", "true"], {
boolean: ["t", "verbose"],
default: { verbose: true }
@@ -70,7 +70,7 @@ test(function flagBooleanValue() {
assertEquals(typeof argv.t, "boolean");
});
-test(function newlinesInParams() {
+test(function newlinesInParams(): void {
const args = parse(["-s", "X\nX"]);
assertEquals(args, { _: [], s: "X\nX" });
@@ -82,7 +82,7 @@ test(function newlinesInParams() {
assertEquals(args2, { _: [], s: "X\nX" });
});
-test(function strings() {
+test(function strings(): void {
const s = parse(["-s", "0001234"], { string: "s" }).s;
assertEquals(s, "0001234");
assertEquals(typeof s, "string");
@@ -92,7 +92,7 @@ test(function strings() {
assertEquals(typeof x, "string");
});
-test(function stringArgs() {
+test(function stringArgs(): void {
const s = parse([" ", " "], { string: "_" })._;
assertEquals(s.length, 2);
assertEquals(typeof s[0], "string");
@@ -101,7 +101,7 @@ test(function stringArgs() {
assertEquals(s[1], " ");
});
-test(function emptyStrings() {
+test(function emptyStrings(): void {
const s = parse(["-s"], { string: "s" }).s;
assertEquals(s, "");
assertEquals(typeof s, "string");
@@ -119,7 +119,7 @@ test(function emptyStrings() {
assertEquals(letters.t, "");
});
-test(function stringAndAlias() {
+test(function stringAndAlias(): void {
const x = parse(["--str", "000123"], {
string: "s",
alias: { s: "str" }
@@ -141,7 +141,7 @@ test(function stringAndAlias() {
assertEquals(typeof y.s, "string");
});
-test(function slashBreak() {
+test(function slashBreak(): void {
assertEquals(parse(["-I/foo/bar/baz"]), { I: "/foo/bar/baz", _: [] });
assertEquals(parse(["-xyz/foo/bar/baz"]), {
x: true,
@@ -151,7 +151,7 @@ test(function slashBreak() {
});
});
-test(function alias() {
+test(function alias(): void {
const argv = parse(["-f", "11", "--zoom", "55"], {
alias: { z: "zoom" }
});
@@ -160,7 +160,7 @@ test(function alias() {
assertEquals(argv.f, 11);
});
-test(function multiAlias() {
+test(function multiAlias(): void {
const argv = parse(["-f", "11", "--zoom", "55"], {
alias: { z: ["zm", "zoom"] }
});
@@ -170,7 +170,7 @@ test(function multiAlias() {
assertEquals(argv.f, 11);
});
-test(function nestedDottedObjects() {
+test(function nestedDottedObjects(): void {
const argv = parse([
"--foo.bar",
"3",
diff --git a/flags/short_test.ts b/flags/short_test.ts
index 700902dd7..f624381b1 100755
--- a/flags/short_test.ts
+++ b/flags/short_test.ts
@@ -3,12 +3,12 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function numbericShortArgs() {
+test(function numbericShortArgs(): void {
assertEquals(parse(["-n123"]), { n: 123, _: [] });
assertEquals(parse(["-123", "456"]), { 1: true, 2: true, 3: 456, _: [] });
});
-test(function short() {
+test(function short(): void {
assertEquals(parse(["-b"]), { b: true, _: [] });
assertEquals(parse(["foo", "bar", "baz"]), { _: ["foo", "bar", "baz"] });
assertEquals(parse(["-cats"]), { c: true, a: true, t: true, s: true, _: [] });
@@ -27,7 +27,7 @@ test(function short() {
});
});
-test(function mixedShortBoolAndCapture() {
+test(function mixedShortBoolAndCapture(): void {
assertEquals(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
f: true,
p: 555,
@@ -36,7 +36,7 @@ test(function mixedShortBoolAndCapture() {
});
});
-test(function shortAndLong() {
+test(function shortAndLong(): void {
assertEquals(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
f: true,
p: 555,
diff --git a/flags/stop_early_test.ts b/flags/stop_early_test.ts
index 70194adfe..144a2921f 100755
--- a/flags/stop_early_test.ts
+++ b/flags/stop_early_test.ts
@@ -4,7 +4,7 @@ import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
// stops parsing on the first non-option when stopEarly is set
-test(function stopParsing() {
+test(function stopParsing(): void {
const argv = parse(["--aaa", "bbb", "ccc", "--ddd"], {
stopEarly: true
});
diff --git a/flags/unknown_test.ts b/flags/unknown_test.ts
index fcb47e36b..84d4db899 100755
--- a/flags/unknown_test.ts
+++ b/flags/unknown_test.ts
@@ -3,7 +3,7 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function booleanAndAliasIsNotUnknown() {
+test(function booleanAndAliasIsNotUnknown(): void {
const unknown = [];
function unknownFn(arg): boolean {
unknown.push(arg);
@@ -22,7 +22,7 @@ test(function booleanAndAliasIsNotUnknown() {
assertEquals(unknown, ["--derp", "-d"]);
});
-test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown() {
+test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown(): void {
const unknown = [];
function unknownFn(arg): boolean {
unknown.push(arg);
@@ -39,7 +39,7 @@ test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown() {
});
});
-test(function stringAndAliasIsNotUnkown() {
+test(function stringAndAliasIsNotUnkown(): void {
const unknown = [];
function unknownFn(arg): boolean {
unknown.push(arg);
@@ -58,7 +58,7 @@ test(function stringAndAliasIsNotUnkown() {
assertEquals(unknown, ["--derp", "-d"]);
});
-test(function defaultAndAliasIsNotUnknown() {
+test(function defaultAndAliasIsNotUnknown(): void {
const unknown = [];
function unknownFn(arg): boolean {
unknown.push(arg);
@@ -77,7 +77,7 @@ test(function defaultAndAliasIsNotUnknown() {
assertEquals(unknown, []);
});
-test(function valueFollowingDoubleHyphenIsNotUnknown() {
+test(function valueFollowingDoubleHyphenIsNotUnknown(): void {
const unknown = [];
function unknownFn(arg): boolean {
unknown.push(arg);
diff --git a/flags/whitespace_test.ts b/flags/whitespace_test.ts
index f0f24703c..9e6ba7115 100755
--- a/flags/whitespace_test.ts
+++ b/flags/whitespace_test.ts
@@ -3,6 +3,6 @@ import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
-test(function whitespaceShouldBeWhitespace() {
+test(function whitespaceShouldBeWhitespace(): void {
assertEquals(parse(["-x", "\t"]).x, "\t");
});