Skip to content

Commit

Permalink
feat(cli.ts, commit.ts): add --yes flag to skip commit confirmation…
Browse files Browse the repository at this point in the history
… prompt (di-sukharev#341)

docs(README.md): document the `--yes` flag usage in README for user guidance
  • Loading branch information
ignlg authored and drewpayment committed May 25, 2024
1 parent b8a60f4 commit 18fb6e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -29,7 +35,7 @@ cli(
if (await isHookCalled()) {
prepareCommitMessageHook();
} else {
commit(extraArgs, false, flags.fgm);
commit(extraArgs, false, flags.fgm, flags.yes);
}
},
extraArgs
Expand Down
11 changes: 7 additions & 4 deletions src/commands/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const checkMessageTemplate = (extraArgs: string[]): string | false => {
const generateCommitMessageFromGitDiff = async (
diff: string,
extraArgs: string[],
fullGitMojiSpec: boolean
fullGitMojiSpec: boolean,
skipCommitConfirmation: boolean
): Promise<void> => {
await assertGitRepo();
const commitSpinner = spinner();
Expand Down Expand Up @@ -76,7 +77,7 @@ ${commitMessage}
${chalk.grey('——————————————————')}`
);

const isCommitConfirmedByUser = await confirm({
const isCommitConfirmedByUser = skipCommitConfirmation || await confirm({
message: 'Confirm the commit message?'
});

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -250,7 +252,8 @@ export async function commit(
generateCommitMessageFromGitDiff(
await getDiff({ files: stagedFiles }),
extraArgs,
fullGitMojiSpec
fullGitMojiSpec,
skipCommitConfirmation
)
);

Expand Down

0 comments on commit 18fb6e1

Please sign in to comment.