MCPcopy Create free account
hub / github.com/conventional-changelog/commitlint / main

Function main

@commitlint/cli/src/cli.ts:198–415  ·  view source on GitHub ↗
(args: MainArgs)

Source from the content-addressed store, hash-verified

196}
197
198async 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");

Callers 1

cli.tsFile · 0.70

Calls 12

resolveArgsFunction · 0.85
normalizeFlagsFunction · 0.85
checkFromStdinFunction · 0.85
stdinFunction · 0.85
checkFromRepositoryFunction · 0.85
selectParserOptsFunction · 0.85
loadFormatterFunction · 0.85
logMethod · 0.80
filterMethod · 0.80
loadConfigFunction · 0.70
lintFunction · 0.50
formatFunction · 0.50

Tested by

no test coverage detected