Skip to content

Commit b34375b

Browse files
committed
fix build
Signed-off-by: shmck <[email protected]>
1 parent de0b19c commit b34375b

File tree

4 files changed

+16
-48
lines changed

4 files changed

+16
-48
lines changed

Diff for: src/create.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ async function create(args: string[]): Promise<void> {
1717
// dir - default .
1818
const dir = !args.length || args[0].match(/^-/) ? "." : args[0];
1919
// lang - default js
20-
const lang = getArg(args, { name: "lang", alias: "l" }) || "js";
20+
const lang: string = getArg(args, { name: "lang", alias: "l" }) || "js";
2121
// testRunner - default mocha
22-
const testRunner =
22+
const testRunner: string =
2323
getArg(args, { name: "testRunner", alias: "t" }) || "mocha";
2424

2525
// validate lang

Diff for: src/utils/args.ts

+7-30
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
type ArgValueParams = {
22
name: string;
33
alias?: string;
4-
type?: "string" | "bool" | "number";
54
};
65

7-
function checkValue<T>(
8-
args: string[],
9-
string: string,
10-
isBool: boolean
11-
): string | null {
6+
function checkValue<T>(args: string[], string: string): string | null {
127
const nameIndex = args.indexOf(string);
138
if (nameIndex >= 0) {
149
const nextArg = args[nameIndex + 1];
1510

1611
if (nextArg !== undefined) {
1712
const nextIsCommand = !!nextArg.match(/^\-/);
1813
if (nextIsCommand) {
19-
return isBool ? "true" : null;
14+
return null;
2015
}
2116
return nextArg;
2217
} else {
2318
// no secondary set value
24-
return isBool ? "true" : null;
19+
return null;
2520
}
2621
}
2722
return null;
@@ -30,35 +25,17 @@ function checkValue<T>(
3025
export function getArg<T>(
3126
args: string[],
3227
options: ArgValueParams
33-
): string | boolean | number | null {
28+
): string | null {
3429
let stringValue: null | string = null;
35-
const isBool = options.type === "bool";
3630

3731
if (options.alias) {
3832
const aliasString = `-${options.alias}`;
39-
stringValue = checkValue(args, aliasString, isBool);
33+
stringValue = checkValue(args, aliasString);
4034
}
4135
if (!stringValue) {
4236
const nameString = `--${options.name}`;
43-
stringValue = checkValue(args, nameString, isBool);
44-
}
45-
46-
if (stringValue === null) {
47-
return null;
48-
}
49-
50-
if (!options.type) {
51-
options.type = "string";
37+
stringValue = checkValue(args, nameString);
5238
}
5339

54-
// coerce type
55-
switch (options.type) {
56-
case "bool":
57-
return (stringValue || "").toLowerCase() !== "false";
58-
case "number":
59-
return Number(stringValue);
60-
case "string":
61-
default:
62-
return stringValue;
63-
}
40+
return stringValue;
6441
}

Diff for: src/validate.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ async function validate(args: string[]) {
2222

2323
// -y --yaml - default coderoad-config.yml
2424
const options: Options = {
25-
// @ts-ignore
26-
yaml:
27-
getArg(args, { name: "yaml", alias: "y", type: "string" }) ||
28-
"coderoad.yaml",
29-
// @ts-ignore
30-
clean: getArg(args, { name: "clean", alias: "c", type: "bool" }),
25+
yaml: getArg(args, { name: "yaml", alias: "y" }) || "coderoad.yaml",
26+
clean: getArg(args, { name: "clean", alias: "c" }) !== "false",
3127
};
3228

3329
const _yaml: string = await fs.readFile(

Diff for: tests/args.test.ts

+5-10
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,39 @@ describe("args", () => {
2626
const result = getArg(args, {
2727
name: "someBool",
2828
alias: "sb",
29-
type: "bool",
3029
});
31-
expect(result).toBe(true);
30+
expect(result).toBe("true");
3231
});
3332
it("should convert bool string to false", () => {
3433
const args = ["--someBool", "false"];
3534
const result = getArg(args, {
3635
name: "someBool",
3736
alias: "sb",
38-
type: "bool",
3937
});
40-
expect(result).toBe(false);
38+
expect(result).toBe("false");
4139
});
4240
it("should default value to true if no next value", () => {
4341
const args = ["--someBool"];
4442
const result = getArg(args, {
4543
name: "someBool",
4644
alias: "sb",
47-
type: "bool",
4845
});
49-
expect(result).toBe(true);
46+
expect(result).toBe(null);
5047
});
5148
it("should default value to true if next value is --name", () => {
5249
const args = ["--someBool", "--someOtherBool"];
5350
const result = getArg(args, {
5451
name: "someBool",
5552
alias: "sb",
56-
type: "bool",
5753
});
58-
expect(result).toBe(true);
54+
expect(result).toBe(null);
5955
});
6056
it("should default value to true if next value is -alias", () => {
6157
const args = ["--someBool", "-a"];
6258
const result = getArg(args, {
6359
name: "someBool",
6460
alias: "sb",
65-
type: "bool",
6661
});
67-
expect(result).toBe(true);
62+
expect(result).toBe(null);
6863
});
6964
});

0 commit comments

Comments
 (0)