|
| 1 | +# @commit-generator/cli |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | + <img src="../../docs/static/demo.gif"> |
| 5 | +</p> |
| 6 | + |
| 7 | +This package provides a CLI tool for generating commit messages based on Git diffs and AI models. It offers configurable commit message generation, editing, and validation. |
| 8 | + |
| 9 | +## 📌 Table of Contents |
| 10 | +- [Installation](#installation) |
| 11 | +- [Usage](#usage) |
| 12 | + - [Default Workflow](#default-workflow) |
| 13 | + - [Manual Generation](#manual-generation) |
| 14 | + - [Validate a Commit Message](#validate-a-commit-message) |
| 15 | + - [Validate the Last Commit Message](#validate-the-last-commit-message) |
| 16 | + - [Persistent Configuration](#persistent-configuration) |
| 17 | + - [Dynamic Configuration](#dynamic-configuration) |
| 18 | +- [Configuration Options](#configuration-options) |
| 19 | +- [License](#-license) |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +To use this package in your project, install it globally: |
| 24 | + |
| 25 | +```bash |
| 26 | +pnpm install -g @commit-generator/cli |
| 27 | +``` |
| 28 | + |
| 29 | +To set up the configuration, run: |
| 30 | + |
| 31 | +```bash |
| 32 | +commitgen config init |
| 33 | +``` |
| 34 | + |
| 35 | +This will launch an interactive prompt, allowing you to configure your AI model for commit message generation. |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +Once installed, you can use the CLI with `commitgen <command>`. |
| 40 | + |
| 41 | +### Default Workflow |
| 42 | + |
| 43 | +To begin, stage your files: |
| 44 | + |
| 45 | +```bash |
| 46 | +git add . |
| 47 | +``` |
| 48 | + |
| 49 | +Then run: |
| 50 | + |
| 51 | +```bash |
| 52 | +commitgen |
| 53 | +``` |
| 54 | + |
| 55 | +This will open an interactive prompt, where you can provide additional context to improve message precision. After completion, the following options are available: |
| 56 | +- Regenerate the commit message |
| 57 | +- Edit the message (opens the default text editor) |
| 58 | +- Commit the message |
| 59 | +- Exit the prompt |
| 60 | + |
| 61 | +### Manual generation |
| 62 | + |
| 63 | +If you prefer to bypass the interactive prompt, use the following command to generate a commit message: |
| 64 | + |
| 65 | +```bash |
| 66 | +commitgen generate |
| 67 | +``` |
| 68 | + |
| 69 | +This command will only generate the commit message without committing. You can then edit it with: |
| 70 | + |
| 71 | +```bash |
| 72 | +commitgen edit |
| 73 | +``` |
| 74 | + |
| 75 | +Finally, to commit: |
| 76 | + |
| 77 | +```bash |
| 78 | +commitgen commit |
| 79 | +``` |
| 80 | + |
| 81 | +### Validate a Commit Message |
| 82 | + |
| 83 | +To validate a commit message, use the following command: |
| 84 | + |
| 85 | +```bash |
| 86 | +commitgen validate <message> |
| 87 | +``` |
| 88 | + |
| 89 | +This compares the commit message with the staged diff and checks whether it adheres to best practices. If necessary, it will generate an improved commit message. |
| 90 | + |
| 91 | +To commit the generated message, run: |
| 92 | + |
| 93 | +```bash |
| 94 | +commitgen commit |
| 95 | +``` |
| 96 | + |
| 97 | +### Validate the Last Commit Message |
| 98 | + |
| 99 | +To validate the most recent commit message, run: |
| 100 | + |
| 101 | +```bash |
| 102 | +commitgen validate |
| 103 | +``` |
| 104 | + |
| 105 | +If needed, amend the commit message with: |
| 106 | + |
| 107 | +```bash |
| 108 | +commitgen amend |
| 109 | +``` |
| 110 | + |
| 111 | +### Persistent Configuration |
| 112 | + |
| 113 | +You can set the CLI configuration with: |
| 114 | + |
| 115 | +```bash |
| 116 | +commit config init |
| 117 | +``` |
| 118 | + |
| 119 | +To set a configuration value: |
| 120 | + |
| 121 | +```bash |
| 122 | +commitgen config set <key>=value |
| 123 | +# Example: commitgen config set provider=openai openai.key=some_key |
| 124 | +# Example: commitgen config set exclude.files="pnpm-lock.yaml,package-lock.json" |
| 125 | +``` |
| 126 | + |
| 127 | +To unset a configuration value: |
| 128 | + |
| 129 | +```bash |
| 130 | +commitgen config unset <key> |
| 131 | +# Example: commitgen config unset exclude.files |
| 132 | +``` |
| 133 | + |
| 134 | +To list the active configuration: |
| 135 | + |
| 136 | +```bash |
| 137 | +commitgen config list |
| 138 | +``` |
| 139 | + |
| 140 | +### Dynamic Configuration |
| 141 | + |
| 142 | +You can dynamically change the configuration using environment variables with the `commit_gen_config_` prefix. Replace `.` with `_`. |
| 143 | + |
| 144 | +For example: |
| 145 | + |
| 146 | +```bash |
| 147 | +$env:commit_gen_config_openai_key = "some_key" # PowerShell |
| 148 | +set commit_gen_config_openai_key=some_key # CMD |
| 149 | +export commit_gen_config_openai_key="some_key" # Linux |
| 150 | +``` |
| 151 | + |
| 152 | +You can also use `--<key>=<value>` for CLI options: |
| 153 | + |
| 154 | +```bash |
| 155 | +commitgen config list --provider=ollama |
| 156 | +``` |
| 157 | + |
| 158 | +## Configuration options |
| 159 | + |
| 160 | +| Key | Type | Description | |
| 161 | +|-----------------|-----------------|-----------------------------------------| |
| 162 | +| `provider` | `string` | The AI provider to use | |
| 163 | +| `openai.key` | `string` | The OpenAi authentication key | |
| 164 | +| `ollama.model` | `string` | The model to use in Ollama | |
| 165 | +| `exclude.files` | `Array<string>` | Files to exclude from the diff analysis | |
| 166 | + |
| 167 | +## License |
| 168 | + |
| 169 | +This package is licensed under the MIT License. |
0 commit comments