@@ -2,9 +2,23 @@ import { existsSync, writeFileSync } from "fs";
22import { join } from "path" ;
33import { Generator , recipe , testcase , generateMode } from "./" ;
44
5- // get recipe and output from command line
5+ if (
6+ process . argv . findIndex ( ( arg ) => arg === "--version" ) !== - 1 ||
7+ process . argv . findIndex ( ( arg ) => arg === "-v" ) !== - 1 ||
8+ process . argv . findIndex ( ( arg ) => arg === "-V" ) !== - 1
9+ ) {
10+ console . log ( "testcase-gen version: " + "\u001b[1;93m" + require ( "../package.json" ) . version + "\u001b[0m" ) ;
11+ console . log ( "Usage: testcase-gen --recipe [recipe] --output [output] --mode [mode]" ) ;
12+ console . log ( "\t--recipe (-r): Recipe JS File Path." ) ;
13+ console . log ( "\t--output (-o): Output File Path." ) ;
14+ console . log ( '\t--mode (-m): Generate Mode. "simple" or "normal".' ) ;
15+ console . log ( "\t--version (-V) or (-v): Show version." ) ;
16+ console . log ( "Homepage: " + "\u001b[94m" + require ( "../package.json" ) . homepage + "\u001b[0m" ) ;
17+ process . exit ( 0 ) ;
18+ }
19+
620let recipePath = join ( process . cwd ( ) , "recipe.js" ) ,
7- outputPath = join ( process . cwd ( ) , "testcases.txt" ) ,
21+ outputPath = "" ,
822 mode : generateMode = "simple" ;
923if ( process . argv . findIndex ( ( arg ) => arg === "--recipe" ) !== - 1 || process . argv . findIndex ( ( arg ) => arg === "-r" ) !== - 1 ) {
1024 recipePath =
@@ -46,9 +60,11 @@ const testcases = generator.gen(mode);
4660const EndTime = Date . now ( ) ;
4761
4862if ( mode === "simple" ) {
63+ if ( ! outputPath ) outputPath = join ( process . cwd ( ) , "testcases.txt" ) ;
4964 writeFileSync ( outputPath , testcases as string , "utf-8" ) ;
50- console . log ( "\033 [92m" + `Testcases generated in ${ EndTime - StartTime } ms at ${ outputPath } .` + "\033 [0m" ) ;
65+ console . log ( "\u001b [92m" + `Testcases generated in ${ EndTime - StartTime } ms at ${ outputPath } .` + "\u001b [0m" ) ;
5166} else {
67+ if ( ! outputPath ) outputPath = join ( process . cwd ( ) , "testcases.json" ) ;
5268 writeFileSync ( outputPath , JSON . stringify ( testcases as testcase [ ] , null , 2 ) , "utf-8" ) ;
53- console . log ( "\033 [92m" + `${ ( testcases as testcase [ ] ) . length } testcases generated in ${ EndTime - StartTime } ms at ${ outputPath } .` + "\033 [0m" ) ;
69+ console . log ( "\u001b [92m" + `${ ( testcases as testcase [ ] ) . length } testcases generated in ${ EndTime - StartTime } ms at ${ outputPath } .` + "\u001b [0m" ) ;
5470}
0 commit comments