Add the ability to return only the code of validation command #6

Merged
CTO merged 3 commits from develop into main 2023-08-21 15:37:12 +00:00
Showing only changes of commit 8ab631549a - Show all commits

View File

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