-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd): add commit and complete subcommands
This commit adds the `commit` and `complete` subcommands to the command-line interface. The `commit` subcommand allows users to commit their changes to the codebase, while the `complete` subcommand generates tab-completion scripts for different shells. The `commit` subcommand includes the following changes: - Added a `commit` module with the `Cmd` struct. - Added a `commit::tests` module for unit tests. - Added a `commit::Cmd::api_key` method to retrieve the API key. - Added a `commit::Cmd::prompt` method to retrieve the prompt. - Implemented the `Run` trait for the `commit::Cmd` struct. - Added a `sanitize` function to sanitize commit messages. The `complete` subcommand includes the following changes: - Added a `complete` module with the `Cmd` struct. - Added a `complete::Cmd::shell` field to specify the shell for which to generate the completion script. - Implemented the `Run` trait for the `complete::Cmd` struct. The `common::log` module includes the following changes: - Added a `Level` enum to represent different log levels. - Implemented the `ValueEnum` trait for the `Level` enum. - Implemented the `Display` trait for the `Level` enum. - Added a conversion from `Level` to `LevelFilter`. The `external::bitwarden` module includes the following changes: - Added debug logging for the command executed to retrieve the API key. The `external::git` module includes the following changes: - Added debug logging for the commands executed to get the status and diff. The `external::pre_commit` module includes the following changes: - Added debug logging for the command executed to run the pre-commit hook. The commit message describes the changes made to the codebase and provides a brief explanation of why the changes were made.
- Loading branch information
Showing
11 changed files
with
206 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Command-Line Help for `ai-commit-cli` | ||
|
||
This document contains the help content for the `ai-commit-cli` command-line program. | ||
|
||
**Command Overview:** | ||
|
||
- [Command-Line Help for `ai-commit-cli`](#command-line-help-for-ai-commit-cli) | ||
- [`ai-commit-cli`](#ai-commit-cli) - [**Subcommands:**](#subcommands) - [**Options:**](#options) | ||
- [`ai-commit-cli commit`](#ai-commit-cli-commit) - [**Options:**](#options-1) | ||
- [`ai-commit-cli complete`](#ai-commit-cli-complete) - [**Arguments:**](#arguments) | ||
|
||
## `ai-commit-cli` | ||
|
||
**Usage:** `ai-commit-cli [OPTIONS] <COMMAND>` | ||
|
||
###### **Subcommands:** | ||
|
||
- `commit` — | ||
- `complete` — Generate tab-completion scripts for your shell | ||
|
||
###### **Options:** | ||
|
||
- `-l`, `--log-level <LOG_LEVEL>` | ||
|
||
Default value: `info` | ||
|
||
Possible values: `trace`, `debug`, `info`, `warn`, `error` | ||
|
||
## `ai-commit-cli commit` | ||
|
||
**Usage:** `ai-commit-cli commit [OPTIONS]` | ||
|
||
###### **Options:** | ||
|
||
- `-a`, `--api-key <API_KEY>` — If not provided, will use `bw get notes OPENAI_API_KEY` | ||
- `-e`, `--exclude <EXCLUDE>` | ||
|
||
Default values: `*-lock.*`, `*.lock` | ||
|
||
- `-i`, `--include <INCLUDE>` | ||
- `--no-pre-commit` | ||
|
||
Default value: `false` | ||
|
||
- `-p`, `--prompt <PROMPT>` | ||
- `--prompt-file <PROMPT_FILE>` | ||
- `--model <MODEL>` — ID of the model to use | ||
|
||
Default value: `gpt-3.5-turbo-16k` | ||
|
||
- `--max-tokens <MAX_TOKENS>` — The maximum number of tokens to generate in the chat completion | ||
|
||
Default value: `500` | ||
|
||
- `-n <N>` — How many chat completion choices to generate for each input message | ||
|
||
Default value: `1` | ||
|
||
- `--temperature <TEMPERATURE>` — What sampling temperature to use, between 0 and 2 | ||
|
||
Default value: `0` | ||
|
||
- `--top-p <TOP_P>` — An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass | ||
|
||
Default value: `0.1` | ||
|
||
## `ai-commit-cli complete` | ||
|
||
Generate tab-completion scripts for your shell | ||
|
||
$ ai-commit-cli complete fish >$HOME/.local/share/fish/vendor_completions.d $ ai-commit-cli complete fish >/usr/local/share/fish/vendor_completions.d | ||
|
||
**Usage:** `ai-commit-cli complete <SHELL>` | ||
|
||
###### **Arguments:** | ||
|
||
- `<SHELL>` | ||
|
||
Possible values: `markdown`, `bash`, `elvish`, `fish`, `powershell`, `zsh` | ||
|
||
<hr/> | ||
|
||
<small><i> | ||
This document was generated automatically by | ||
<a href="https://crates.io/crates/clap-markdown"><code>clap-markdown</code></a>. | ||
</i></small> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,56 @@ | ||
use clap::{Args, CommandFactory}; | ||
use clap::{builder::PossibleValue, Args, CommandFactory, ValueEnum}; | ||
use clap_complete::Shell; | ||
|
||
use crate::cmd::Run; | ||
|
||
/// Generate tab-completion scripts for your shell | ||
/// | ||
/// $ ai-commit-cli complete fish >$HOME/.local/share/fish/vendor_completions.d | ||
/// $ ai-commit-cli complete fish >/usr/local/share/fish/vendor_completions.d | ||
#[derive(Debug, Args)] | ||
pub struct Cmd { | ||
shell: Shell, | ||
shell: Generator, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
enum Generator { | ||
Markdown, | ||
Shell(Shell), | ||
} | ||
|
||
impl ValueEnum for Generator { | ||
fn value_variants<'a>() -> &'a [Self] { | ||
&[ | ||
Self::Markdown, | ||
Self::Shell(Shell::Bash), | ||
Self::Shell(Shell::Elvish), | ||
Self::Shell(Shell::Fish), | ||
Self::Shell(Shell::PowerShell), | ||
Self::Shell(Shell::Zsh), | ||
] | ||
} | ||
|
||
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> { | ||
match self { | ||
Self::Markdown => Some(PossibleValue::new("markdown")), | ||
Self::Shell(shell) => shell.to_possible_value(), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Run for Cmd { | ||
async fn run(&self) -> anyhow::Result<()> { | ||
let cmd = &mut crate::cmd::Cmd::command(); | ||
clap_complete::generate( | ||
self.shell, | ||
cmd, | ||
cmd.get_name().to_string(), | ||
&mut std::io::stdout(), | ||
); | ||
match self.shell { | ||
Generator::Markdown => clap_markdown::print_help_markdown::<crate::cmd::Cmd>(), | ||
Generator::Shell(shell) => clap_complete::generate( | ||
shell, | ||
cmd, | ||
cmd.get_name().to_string(), | ||
&mut std::io::stdout(), | ||
), | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.