Skip to content

Commit 3125404

Browse files
authored
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
1 parent f814c6b commit 3125404

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ This is due to limit the number of tokens sent in each request. However, if you
8484
oco --fgm
8585
```
8686

87+
#### Skip Commit Confirmation
88+
89+
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:
90+
91+
```
92+
oco --yes
93+
```
94+
8795
## Configuration
8896

8997
### Local per repo configuration

src/cli.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ cli(
1818
name: 'opencommit',
1919
commands: [configCommand, hookCommand, commitlintConfigCommand],
2020
flags: {
21-
fgm: Boolean
21+
fgm: Boolean,
22+
yes: {
23+
type: Boolean,
24+
alias: 'y',
25+
description: 'Skip commit confirmation prompt',
26+
default: false
27+
}
2228
},
2329
ignoreArgv: (type) => type === 'unknown-flag' || type === 'argument',
2430
help: { description: packageJSON.description }
@@ -29,7 +35,7 @@ cli(
2935
if (await isHookCalled()) {
3036
prepareCommitMessageHook();
3137
} else {
32-
commit(extraArgs, false, flags.fgm);
38+
commit(extraArgs, false, flags.fgm, flags.yes);
3339
}
3440
},
3541
extraArgs

src/commands/commit.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ const checkMessageTemplate = (extraArgs: string[]): string | false => {
4141
const generateCommitMessageFromGitDiff = async (
4242
diff: string,
4343
extraArgs: string[],
44-
fullGitMojiSpec: boolean
44+
fullGitMojiSpec: boolean,
45+
skipCommitConfirmation: boolean
4546
): Promise<void> => {
4647
await assertGitRepo();
4748
const commitSpinner = spinner();
@@ -76,7 +77,7 @@ ${commitMessage}
7677
${chalk.grey('——————————————————')}`
7778
);
7879

79-
const isCommitConfirmedByUser = await confirm({
80+
const isCommitConfirmedByUser = skipCommitConfirmation || await confirm({
8081
message: 'Confirm the commit message?'
8182
});
8283

@@ -178,7 +179,8 @@ ${chalk.grey('——————————————————')}`
178179
export async function commit(
179180
extraArgs: string[] = [],
180181
isStageAllFlag: Boolean = false,
181-
fullGitMojiSpec: boolean = false
182+
fullGitMojiSpec: boolean = false,
183+
skipCommitConfirmation: boolean = false
182184
) {
183185
if (isStageAllFlag) {
184186
const changedFiles = await getChangedFiles();
@@ -250,7 +252,8 @@ export async function commit(
250252
generateCommitMessageFromGitDiff(
251253
await getDiff({ files: stagedFiles }),
252254
extraArgs,
253-
fullGitMojiSpec
255+
fullGitMojiSpec,
256+
skipCommitConfirmation
254257
)
255258
);
256259

0 commit comments

Comments
 (0)