(argv)
| 110 | } |
| 111 | |
| 112 | export async function runCli(argv) { |
| 113 | const [command, ...rest] = argv; |
| 114 | if (!command || command === "--help" || command === "-h") { |
| 115 | process.stdout.write(usage()); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | const { positional, options } = parseOptions(rest); |
| 120 | if (options.help) { |
| 121 | process.stdout.write(usage()); |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | if (command === "analyze") { |
| 126 | if (positional.length < 1) { |
| 127 | throw new Error("Missing target path.\n\n" + usage()); |
| 128 | } |
| 129 | const result = await analyzePath(positional[0], { |
| 130 | metricPackManifests: options.metricPackManifests, |
| 131 | observedUsagePaths: options.observedUsagePaths, |
| 132 | }); |
| 133 | if (options.briefOut) { |
| 134 | await writeText(path.resolve(options.briefOut), `${JSON.stringify(result.improvementBrief, null, 2)}\n`); |
| 135 | } |
| 136 | await emit(result, options.format, options.output); |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | if (command === "report") { |
| 141 | if (positional.length < 1) { |
| 142 | throw new Error("Missing result.json path.\n\n" + usage()); |
| 143 | } |
| 144 | const result = await readJson(path.resolve(positional[0])); |
| 145 | await emit(result, options.format, options.output); |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | if (command === "compare") { |
| 150 | if (positional.length < 2) { |
| 151 | throw new Error("Missing before/after result paths.\n\n" + usage()); |
| 152 | } |
| 153 | const before = await readJson(path.resolve(positional[0])); |
| 154 | const after = await readJson(path.resolve(positional[1])); |
| 155 | await emit(compareResults(before, after), options.format, options.output); |
| 156 | return; |
| 157 | } |
| 158 | |
| 159 | if (command === "start" || command === "guide") { |
| 160 | if (positional.length < 1) { |
| 161 | throw new Error("Missing target path.\n\n" + usage()); |
| 162 | } |
| 163 | const payload = await buildWorkflowGuide(positional[0], { |
| 164 | goal: options.goal, |
| 165 | request: options.request, |
| 166 | }); |
| 167 | await emit(payload, options.format, options.output); |
| 168 | return; |
| 169 | } |
no test coverage detected