From 312540456abb3fecc7c68256c23fa5853658e782 Mon Sep 17 00:00:00 2001 From: Ignacio Lago Date: Thu, 23 May 2024 16:56:35 +0900 Subject: [PATCH] feat(cli.ts, commit.ts): add `--yes` flag to skip commit confirmation prompt (#341) docs(README.md): document the `--yes` flag usage in README for user guidance --- README.md | 8 ++++++++ src/cli.ts | 10 ++++++++-- src/commands/commit.ts | 11 +++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b19b7f9..20671b0 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,14 @@ This is due to limit the number of tokens sent in each request. However, if you oco --fgm ``` +#### Skip Commit Confirmation + +This flag allows users to automatically commit the changes without having to manually confirm the commit message. This is useful for users who want to streamline the commit process and avoid additional steps. To use this flag, you can run the following command: + +``` +oco --yes +``` + ## Configuration ### Local per repo configuration diff --git a/src/cli.ts b/src/cli.ts index 5bd204e..e225a73 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -18,7 +18,13 @@ cli( name: 'opencommit', commands: [configCommand, hookCommand, commitlintConfigCommand], flags: { - fgm: Boolean + fgm: Boolean, + yes: { + type: Boolean, + alias: 'y', + description: 'Skip commit confirmation prompt', + default: false + } }, ignoreArgv: (type) => type === 'unknown-flag' || type === 'argument', help: { description: packageJSON.description } @@ -29,7 +35,7 @@ cli( if (await isHookCalled()) { prepareCommitMessageHook(); } else { - commit(extraArgs, false, flags.fgm); + commit(extraArgs, false, flags.fgm, flags.yes); } }, extraArgs diff --git a/src/commands/commit.ts b/src/commands/commit.ts index 15b12c2..21b1d70 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -41,7 +41,8 @@ const checkMessageTemplate = (extraArgs: string[]): string | false => { const generateCommitMessageFromGitDiff = async ( diff: string, extraArgs: string[], - fullGitMojiSpec: boolean + fullGitMojiSpec: boolean, + skipCommitConfirmation: boolean ): Promise => { await assertGitRepo(); const commitSpinner = spinner(); @@ -76,7 +77,7 @@ ${commitMessage} ${chalk.grey('——————————————————')}` ); - const isCommitConfirmedByUser = await confirm({ + const isCommitConfirmedByUser = skipCommitConfirmation || await confirm({ message: 'Confirm the commit message?' }); @@ -178,7 +179,8 @@ ${chalk.grey('——————————————————')}` export async function commit( extraArgs: string[] = [], isStageAllFlag: Boolean = false, - fullGitMojiSpec: boolean = false + fullGitMojiSpec: boolean = false, + skipCommitConfirmation: boolean = false ) { if (isStageAllFlag) { const changedFiles = await getChangedFiles(); @@ -250,7 +252,8 @@ export async function commit( generateCommitMessageFromGitDiff( await getDiff({ files: stagedFiles }), extraArgs, - fullGitMojiSpec + fullGitMojiSpec, + skipCommitConfirmation ) );