|
| 1 | +export class CommandLineValues { |
| 2 | + public File: string; |
| 3 | + public Dir:string; |
| 4 | + public MaxPathLength:number; |
| 5 | + public MaxPathWidth:number; |
| 6 | + public NoHash:boolean; |
| 7 | + public NumThreads:number; |
| 8 | + public MinCodeLength:number; |
| 9 | + public MaxCodeLength:number; |
| 10 | + public PrettyPrint:boolean; |
| 11 | + public MaxChildId:number; |
| 12 | + public debugMode:boolean; |
| 13 | + public testSetMode:boolean; |
| 14 | + public logDir:string |
| 15 | + |
| 16 | + constructor() { |
| 17 | + this.setArgsDeafultValues(); |
| 18 | + var commandLineArgs = this.getCommandLineArgs(); |
| 19 | + this.updateCommanLineArgs(commandLineArgs); |
| 20 | + } |
| 21 | + |
| 22 | + private setArgsDeafultValues() { |
| 23 | + this.File = null; |
| 24 | + this.Dir = null; |
| 25 | + this.MaxPathLength = 100; |
| 26 | + this.MaxPathWidth = 10; |
| 27 | + this.NoHash = false; |
| 28 | + this.NumThreads = 32; |
| 29 | + this.MinCodeLength = 1; |
| 30 | + this.MaxCodeLength = 10000; |
| 31 | + this.PrettyPrint = false; |
| 32 | + this.MaxChildId = Number.MAX_SAFE_INTEGER; |
| 33 | + this.debugMode = false; |
| 34 | + this.testSetMode = false; |
| 35 | + this.logDir = "TSE_log/"; |
| 36 | + } |
| 37 | + |
| 38 | + private getCommandLineArgs() { |
| 39 | + var optionDefinitions = [ |
| 40 | + { name: 'dir', type: String}, |
| 41 | + { name: 'file', type: String }, |
| 42 | + { name: 'max_path_length', type: Number }, |
| 43 | + { name: 'max_path_width', type: Number }, |
| 44 | + { name: 'no_hash', type: Boolean }, |
| 45 | + { name: 'num_threads', type: Number }, |
| 46 | + { name: 'min_code_len', type: Number }, |
| 47 | + { name: 'max_code_len', type: Number }, |
| 48 | + { name: 'pretty_print', type: Boolean }, |
| 49 | + { name: 'max_child_id', type: Number }, |
| 50 | + { name: 'debug', type: Number }, |
| 51 | + { name: 'test_set', type: Number }, |
| 52 | + { name: 'log_dir', type: String} |
| 53 | + ]; |
| 54 | + const commandLineArgs = require('command-line-args'); |
| 55 | + const options = commandLineArgs(optionDefinitions); |
| 56 | + return options; |
| 57 | + } |
| 58 | + |
| 59 | + private updateCommanLineArgs(commandLineArgs : any) : void { |
| 60 | + if(commandLineArgs.max_path_length){ |
| 61 | + this.MaxPathLength=commandLineArgs.max_path_length; |
| 62 | + } |
| 63 | + if(commandLineArgs.max_path_width){ |
| 64 | + this.MaxPathWidth=commandLineArgs.max_path_width; |
| 65 | + } |
| 66 | + if(commandLineArgs.file){ |
| 67 | + this.File=commandLineArgs.file; |
| 68 | + } |
| 69 | + if(commandLineArgs.dir){ |
| 70 | + this.Dir=commandLineArgs.dir; |
| 71 | + } |
| 72 | + if(commandLineArgs.no_hash){ |
| 73 | + this.NoHash=commandLineArgs.no_hash; |
| 74 | + } |
| 75 | + if(commandLineArgs.num_threads){ |
| 76 | + this.NumThreads=commandLineArgs.num_threads; |
| 77 | + } |
| 78 | + if(commandLineArgs.min_code_len){ |
| 79 | + this.MinCodeLength=commandLineArgs.min_code_len; |
| 80 | + } |
| 81 | + if(commandLineArgs.max_code_len){ |
| 82 | + this.MaxCodeLength=commandLineArgs.max_code_len; |
| 83 | + } |
| 84 | + if(commandLineArgs.pretty_print){ |
| 85 | + this.PrettyPrint=commandLineArgs.pretty_print; |
| 86 | + } |
| 87 | + if(commandLineArgs.max_child_id){ |
| 88 | + this.MaxChildId=commandLineArgs.max_child_id; |
| 89 | + } |
| 90 | + if(commandLineArgs.debug) { |
| 91 | + this.debugMode=commandLineArgs.debug; |
| 92 | + } |
| 93 | + if(commandLineArgs.test_set) { |
| 94 | + this.testSetMode=commandLineArgs.test_set; |
| 95 | + } |
| 96 | + if(commandLineArgs.log_dir) { |
| 97 | + let log_dir: string = commandLineArgs.log_dir; |
| 98 | + if (!commandLineArgs.log_dir.endsWith("/")) log_dir += "/"; |
| 99 | + this.logDir=log_dir; |
| 100 | + } |
| 101 | + } |
| 102 | +} |
0 commit comments