Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb34375b

Browse files
committed
fix build
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parentde0b19c commitb34375b

File tree

4 files changed

+16
-48
lines changed

4 files changed

+16
-48
lines changed

‎src/create.ts

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

2525
// validate lang

‎src/utils/args.ts

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

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

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

3731
if(options.alias){
3832
constaliasString=`-${options.alias}`;
39-
stringValue=checkValue(args,aliasString,isBool);
33+
stringValue=checkValue(args,aliasString);
4034
}
4135
if(!stringValue){
4236
constnameString=`--${options.name}`;
43-
stringValue=checkValue(args,nameString,isBool);
44-
}
45-
46-
if(stringValue===null){
47-
returnnull;
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-
returnNumber(stringValue);
60-
case"string":
61-
default:
62-
returnstringValue;
63-
}
40+
returnstringValue;
6441
}

‎src/validate.ts

Lines changed: 2 additions & 6 deletions
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
constoptions: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=awaitfs.readFile(

‎tests/args.test.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,44 +26,39 @@ describe("args", () => {
2626
constresult=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
constargs=["--someBool","false"];
3534
constresult=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
constargs=["--someBool"];
4442
constresult=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
constargs=["--someBool","--someOtherBool"];
5350
constresult=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
constargs=["--someBool","-a"];
6258
constresult=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)

[8]ページ先頭

©2009-2025 Movatter.jp