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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 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.18.3"
version = "0.18.4"
repository = "https://github.com/Uliboooo/ghost_git_writer"
edition = "2024"
license = "MIT OR Apache-2.0"
Expand Down
56 changes: 44 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum Error {
Rdm(readme_gen::Error),
EnvVar,
NotFoundHome,
NotFoundConfig,
NotFoundConfig(String),
NotFoundLlmField,
NotFoundSelectedModel,
NotFoundDefaultModel,
Expand Down Expand Up @@ -119,14 +119,32 @@ impl Display for Error {
Error::Git(error) => write!(f, "git error: {error}"),
// Error::Cmt(error) => write!(f, "commit gen error: {error}"),
Error::Rdm(error) => write!(f, "readme gen error: {error}"),
Error::NotFoundHome => write!(f, "not found home directory"),
Error::NotFoundConfig => write!(f, "not found config file"),
Error::NotFoundWorkFolder => write!(f, "not found work folder"),
Error::NotFoundHome => write!(
f,
"not found home directory. Please ensure the HOME environment variable is set."
),
Error::NotFoundConfig(ctx) => write!(f, "not found config file. {ctx}"),
Error::NotFoundWorkFolder => write!(
f,
"not found work folder. Please verify the path passed with --path exists."
),
Error::Cancel => write!(f, "commit canceled"),
Error::EnvVar => write!(f, "failed get api key as env var. please set it."),
Error::NotFoundLlmField => write!(f, "not found llm field in config file"),
Error::NotFoundSelectedModel => write!(f, "not found selected model in config"),
Error::NotFoundDefaultModel => write!(f, "not found default model in config"),
Error::EnvVar => write!(
f,
"failed to get API key from environment variable. Please set the appropriate variable (e.g. GGW_GEMINI_API, GGW_OPENAI_API, GGW_ANTHROPIC_API, or GGW_DEEPSEEK_API)."
),
Error::NotFoundLlmField => write!(
f,
"not found 'llms' field in config file. Please add an [llms] section to your config. See the config template for reference."
),
Error::NotFoundSelectedModel => write!(
f,
"not found selected model alias in config. Please verify the alias exists under [llms.models] in your config file."
),
Error::NotFoundDefaultModel => write!(
f,
"not found default model in config. Please set 'default_model' under the [llms] section of your config file."
),
Error::InvalidSemVer(s) => write!(f, "invalid SemVer part from LLM response: {s}"),
}
}
Expand Down Expand Up @@ -163,7 +181,13 @@ fn resolve_config_path<T: AsRef<Path>>(path: &Option<T>) -> Result<PathBuf, Erro
} else if secondary.exists() {
Ok(secondary)
} else {
Err(Error::NotFoundConfig)
Err(Error::NotFoundConfig(format!(
"Searched at '{}' and '{}'. \
Please create a config file at one of those locations. \
You can use the bundled config_template.toml as a starting point.",
primary.display(),
secondary.display()
)))
}
}

Expand Down Expand Up @@ -200,15 +224,23 @@ fn resolve_model(
// `-m gem2`
None => match config {
Some(loaded_config) => loaded_config.llms().clone().ok_or(Error::NotFoundLlmField),
None => Err(Error::NotFoundConfig),
None => Err(Error::NotFoundConfig(
"A config file is required to resolve model aliases. \
Please create ~/.config/ggw/config.toml, or pass the model as \
'provider/model' (e.g. `-m gemini/gemini-2.0-flash`).".to_string()
)),
}?
.get_model(v)
.ok_or(Error::NotFoundSelectedModel),
},
// without mode arg
None => match config {
Some(v) => v.llms().clone().ok_or(Error::NotFoundConfig),
None => Err(Error::NotFoundConfig),
Some(v) => v.llms().clone().ok_or(Error::NotFoundLlmField),
None => Err(Error::NotFoundConfig(
"No config file found and no model specified. \
Please create ~/.config/ggw/config.toml with a default_model, \
or specify a model with `-m provider/model` (e.g. `-m gemini/gemini-2.0-flash`).".to_string()
)),
}?
.get_default()
.ok_or(Error::NotFoundDefaultModel),
Expand Down
Loading