(args: MainArgs)
| 196 | } |
| 197 | |
| 198 | async function main(args: MainArgs): Promise<void> { |
| 199 | const options = await resolveArgs(args); |
| 200 | if (typeof options.edit === "undefined") { |
| 201 | options.edit = false; |
| 202 | } |
| 203 | |
| 204 | const raw = options._; |
| 205 | const flags = normalizeFlags(options); |
| 206 | |
| 207 | try { |
| 208 | if (!fs.statSync(flags.cwd).isDirectory()) { |
| 209 | const err = new CliError( |
| 210 | `The specified --cwd path "${flags.cwd}" is not a directory.`, |
| 211 | pkg.name, |
| 212 | ); |
| 213 | console.error(err.message); |
| 214 | throw err; |
| 215 | } |
| 216 | } catch (e) { |
| 217 | if (e instanceof CliError) { |
| 218 | throw e; |
| 219 | } |
| 220 | const code = (e as NodeJS.ErrnoException).code; |
| 221 | const message = |
| 222 | code === "ENOENT" |
| 223 | ? `The specified --cwd directory "${flags.cwd}" does not exist.` |
| 224 | : `Cannot access the specified --cwd directory "${flags.cwd}": ${code ?? (e as Error).message}`; |
| 225 | const err = new CliError(message, pkg.name); |
| 226 | console.error(err.message); |
| 227 | throw err; |
| 228 | } |
| 229 | |
| 230 | if (typeof options["print-config"] === "string") { |
| 231 | const loaded = await loadConfig(flags); |
| 232 | |
| 233 | switch (options["print-config"]) { |
| 234 | case "json": |
| 235 | console.log(JSON.stringify(loaded)); |
| 236 | return; |
| 237 | |
| 238 | case "text": |
| 239 | default: |
| 240 | console.log(util.inspect(loaded, false, null, options.color)); |
| 241 | return; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | const fromStdin = checkFromStdin(raw, flags); |
| 246 | |
| 247 | if ( |
| 248 | Object.hasOwn(flags, "last") && |
| 249 | (Object.hasOwn(flags, "from") || Object.hasOwn(flags, "to") || flags.edit) |
| 250 | ) { |
| 251 | const err = new CliError( |
| 252 | "Please use the --last flag alone. The --last flag should not be used with --to or --from or --edit.", |
| 253 | pkg.name, |
| 254 | ); |
| 255 | cli.showHelp("log"); |
no test coverage detected