Skip to content
Merged
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
45 changes: 44 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ghost_git_writer"
description = "write a git commit message, README or Diff Summary by LLM services."
version = "0.16.0"
version = "0.17.0"
repository = "https://github.com/Uliboooo/ghost_git_writer"
edition = "2024"
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -32,3 +32,4 @@ easy_storage = "0.4.*"
indicatif = "0.18.*"
unicode-width = "0.2.1"
url = "2.5.7"
atty = "0.2.14"
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ pub struct RootOptions {

#[arg(long = "oneline", help = "show only llm's return for cli pipes")]
oneline: bool,

#[arg(long = "stdin", help = "use stdin as diff content")]
stdin: bool,
}

pub trait DiffOption {
Expand Down
3 changes: 2 additions & 1 deletion src/helper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
fs, io, path::{Path, PathBuf}
fs, io,
path::{Path, PathBuf},
};

// #[derive(Debug)]
Expand Down
8 changes: 4 additions & 4 deletions src/llm.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::fmt::Display;
use crate::cli_helper::Spinner;
use crate::config;
use derive_getters::Getters;
use llm_api_rs::{
self, LlmProvider,
core::{ChatCompletionRequest, ChatMessage},
providers::{Anthropic, DeepSeek, Gemini, OpenAI},
};
use ollama_rs::{Ollama, generation::completion::request::GenerationRequest};
use crate::cli_helper::Spinner;
use crate::config;
use std::fmt::Display;

#[derive(Debug)]
pub enum Error {
Expand Down Expand Up @@ -70,7 +70,7 @@ impl TryFrom<&str> for Provider {
"ollama" => Ok(Self::Ollama),
"openai" => Ok(Self::OpenAI),
"gemini" => Ok(Self::Gemini),
"authropic" => Ok(Self::Anthropic),
"anthropic" => Ok(Self::Anthropic),
"deepseek" => Ok(Self::DeepSeek),
_ => Err(Error::NotSuppoeredProvider),
}
Expand Down
65 changes: 50 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use easy_storage::Storeable;
use std::{
env,
fmt::Display,
fs::OpenOptions,
io::Write,
fs::{File, OpenOptions},
io::{BufRead, BufReader, Read, Write, stdout},
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -251,23 +251,49 @@ async fn main() -> Result<(), Error> {
let extra = root_options.extra().as_ref();

let git_status = get_git_status(&work_path)?;
//
// let diff = if root_options.stdin() {
// todo!()
// } else {
// }

match &cli.subcommand {
cli::Commands::Commit(commit) => {
let diff = {
// 👇 is from pipe.
let diff = if !atty::is(atty::Stream::Stdin) && *root_options.stdin() {
let mut input = String::new();
std::io::stdin().lock().read_to_string(&mut input)?;
stdout().flush()?;
input
} else {
let diff_opt = commit.resolve_diff_commit();
git::get_diff(diff_opt, &work_path)
}?;
git::get_diff(diff_opt, &work_path)?
};

let msg = commit_gen::gen_commit_msg(diff, git_status, model_info, lang, extra).await?;
let conti = || {
let mut tty = BufReader::new(File::open("/dev/tty").unwrap());
stdout().flush().unwrap();
// let mut ans = String::new();
// tty.read_line(&mut ans).unwrap();
print!("continue?(y/n)>");
std::io::stdout().flush().unwrap();
let mut ans = String::new();
tty.read_line(&mut ans).unwrap();

matches!(ans.trim(), "y" | "Y" | "Yes" | "yes")
};
if *commit.get_root_options().oneline() {
println!("{msg}");
Ok(())
} else {
let fd_msg = cli_helper::Printer::from(&msg);
println!("Generated msg:\n{fd_msg}");

if *commit.auto_commit() || yes_no("commit?(y/n)") {
if *commit.auto_commit() ||
//yes_no("commit?(y/n)")
conti()
{
git::git_commit(&work_path, &msg, git_user.0, git_user.1)?;
Ok(())
} else {
Expand Down Expand Up @@ -312,15 +338,20 @@ async fn main() -> Result<(), Error> {
Ok(f.write_all(readme_content.as_bytes())?)
}
}
cli::Commands::SumDiff(_diff_sum) => {
let diff = {
let diff_s = _diff_sum.resolve_diff_commit();
git::get_diff(diff_s, &work_path)
}?;
cli::Commands::SumDiff(diff_sum) => {
let diff = if *root_options.stdin() {
let mut input = String::new();
std::io::stdin().read_to_string(&mut input)?;
input
} else {
let diff_s = diff_sum.resolve_diff_commit();
git::get_diff(diff_s, &work_path)?
};

let res =
diff_sum_gen::sum_diff(diff, git_status, model_info, lang.cloned(), extra.cloned())
.await?;
if *_diff_sum.get_root_options().oneline() {
if *diff_sum.get_root_options().oneline() {
println!("{res}");
Ok(())
} else {
Expand All @@ -329,10 +360,14 @@ async fn main() -> Result<(), Error> {
}
}
cli::Commands::WhichSem(which) => {
let diff = {
let diff = if *root_options.stdin() {
let mut input = String::new();
std::io::stdin().read_to_string(&mut input)?;
input
} else {
let diff_s = which.resolve_diff_commit();
git::get_diff(diff_s, &work_path)
}?;
git::get_diff(diff_s, &work_path)?
};
let res =
which_sem::whichi_sem(diff, git_status, model_info, lang.cloned(), extra.cloned())
.await?;
Expand Down