diff --git a/src/index.ts b/src/index.ts index ba17731..6c7a34c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -420,9 +420,11 @@ program .command("validate") .description("Validate whether a string fits given commit conventions") .argument("[message]", "string for validation") - .action(async (string: string) => { + .option("-C, --code-only", "return code only") + .action(async (string: string, options) => { try { const message = string || fs.readFileSync(0, "utf-8"); + const codeOnly = options.codeOnly ? true : false; const config = await GetConfig(); @@ -439,11 +441,15 @@ program "gm" ); - console.log( - testRegex.test(message) - ? "[rcz]: valid message" - : "[rcz]: invalid message" - ); + if (codeOnly) { + console.log(testRegex.test(message) ? 0 : 1); + } else { + console.log( + testRegex.test(message) + ? "[rcz]: valid message" + : "[rcz]: invalid message" + ); + } } catch (err) { console.log("[rcz]: no stdin found"); }