Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --locale cli flag #265

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ aicommits --all # or -a

> 👉 **Tip:** Use the `aic` alias if `aicommits` is too long for you.

#### Generate with a specific locale

You can generate a commit message with a specific locale by passing in the `--locale <locale>` flag, where 'locale' is the locale code:
```sh
aicommits --locale <locale> # or -l <locale>
```

Consult the list of codes in: https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes.

#### Generate multiple recommendations

Sometimes the recommended commit message isn't the best so you want it to generate a few to pick from. You can generate multiple commit messages at once by passing in the `--generate <i>` flag, where 'i' is the number of generated messages:
Expand Down Expand Up @@ -166,7 +175,7 @@ The OpenAI API key. You can retrieve it from [OpenAI API Keys page](https://plat
#### locale
Default: `en`

The locale to use for the generated commit messages. Consult the list of codes in: https://wikipedia.org/wiki/List_of_ISO_639-1_codes.
The locale to use for the generated commit messages. Consult the list of codes in: https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes.

#### generate

Expand Down
6 changes: 6 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ cli(
* https://git-scm.com/docs/git-commit
*/
flags: {
locale: {
type: String,
description: 'Locale to use for the generated commit messages (default: en)',
alias: 'l',
},
generate: {
type: Number,
description: 'Number of messages to generate (Warning: generating multiple costs more) (default: 1)',
Expand Down Expand Up @@ -58,6 +63,7 @@ cli(
prepareCommitMessageHook();
} else {
aicommits(
argv.flags.locale,
argv.flags.generate,
argv.flags.exclude,
argv.flags.all,
Expand Down
2 changes: 2 additions & 0 deletions src/commands/aicommits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { generateCommitMessage } from '../utils/openai.js';
import { KnownError, handleCliError } from '../utils/error.js';

export default async (
locale: string | undefined,
generate: number | undefined,
excludeFiles: string[],
stageAll: boolean,
Expand Down Expand Up @@ -46,6 +47,7 @@ export default async (
const config = await getConfig({
OPENAI_KEY: env.OPENAI_KEY || env.OPENAI_API_KEY,
proxy: env.https_proxy || env.HTTPS_PROXY || env.http_proxy || env.HTTP_PROXY,
locale: locale?.toString(),
generate: generate?.toString(),
type: commitType?.toString(),
});
Expand Down