refactor: 移除未使用的代码和注释掉的辅助函数
This commit is contained in:
@@ -373,26 +373,26 @@ impl CommitCommand {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper trait for optional builder methods
|
||||
trait CommitBuilderExt {
|
||||
fn scope_opt(self, scope: Option<String>) -> Self;
|
||||
fn body_opt(self, body: Option<String>) -> Self;
|
||||
}
|
||||
// // Helper trait for optional builder methods
|
||||
// trait CommitBuilderExt {
|
||||
// fn scope_opt(self, scope: Option<String>) -> Self;
|
||||
// fn body_opt(self, body: Option<String>) -> Self;
|
||||
// }
|
||||
|
||||
impl CommitBuilderExt for CommitBuilder {
|
||||
fn scope_opt(self, scope: Option<String>) -> Self {
|
||||
if let Some(s) = scope {
|
||||
self.scope(s)
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
// impl CommitBuilderExt for CommitBuilder {
|
||||
// fn scope_opt(self, scope: Option<String>) -> Self {
|
||||
// if let Some(s) = scope {
|
||||
// self.scope(s)
|
||||
// } else {
|
||||
// self
|
||||
// }
|
||||
// }
|
||||
|
||||
fn body_opt(self, body: Option<String>) -> Self {
|
||||
if let Some(b) = body {
|
||||
self.body(b)
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
// fn body_opt(self, body: Option<String>) -> Self {
|
||||
// if let Some(b) = body {
|
||||
// self.body(b)
|
||||
// } else {
|
||||
// self
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -750,7 +750,7 @@ impl ConfigCommand {
|
||||
let manager = self.get_manager(config_path)?;
|
||||
let toml = manager.export()?;
|
||||
|
||||
let export_content = if let Some(path) = output {
|
||||
let export_content = if let Some(_path) = output {
|
||||
let pwd = if let Some(p) = password {
|
||||
p.to_string()
|
||||
} else {
|
||||
|
||||
@@ -240,7 +240,7 @@ impl InitCommand {
|
||||
.or_else(|_| std::env::var(format!("QUICOMMIT_{}_API_KEY", provider.to_uppercase())))
|
||||
.ok();
|
||||
|
||||
if let Some(key) = env_key {
|
||||
if let Some(_key) = env_key {
|
||||
println!("\n{} {}", "✓".green(), "Found API key in environment variable.".green());
|
||||
None
|
||||
} else if keyring_available {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::{AppConfig, GitProfile, TokenConfig};
|
||||
use crate::utils::keyring::{KeyringManager, get_default_base_url, get_default_model, provider_needs_api_key};
|
||||
use anyhow::{bail, Context, Result};
|
||||
use std::collections::HashMap;
|
||||
// use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Configuration manager
|
||||
@@ -64,10 +64,10 @@ impl ConfigManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Force save configuration
|
||||
pub fn force_save(&self) -> Result<()> {
|
||||
self.config.save(&self.config_path)
|
||||
}
|
||||
// /// Force save configuration
|
||||
// pub fn force_save(&self) -> Result<()> {
|
||||
// self.config.save(&self.config_path)
|
||||
// }
|
||||
|
||||
/// Get configuration file path
|
||||
pub fn path(&self) -> &Path {
|
||||
@@ -118,11 +118,11 @@ impl ConfigManager {
|
||||
self.config.profiles.get(name)
|
||||
}
|
||||
|
||||
/// Get mutable profile
|
||||
pub fn get_profile_mut(&mut self, name: &str) -> Option<&mut GitProfile> {
|
||||
self.modified = true;
|
||||
self.config.profiles.get_mut(name)
|
||||
}
|
||||
// /// Get mutable profile
|
||||
// pub fn get_profile_mut(&mut self, name: &str) -> Option<&mut GitProfile> {
|
||||
// self.modified = true;
|
||||
// self.config.profiles.get_mut(name)
|
||||
// }
|
||||
|
||||
/// List all profile names
|
||||
pub fn list_profiles(&self) -> Vec<&String> {
|
||||
@@ -170,10 +170,10 @@ impl ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get profile usage statistics
|
||||
pub fn get_profile_usage(&self, name: &str) -> Option<&super::UsageStats> {
|
||||
self.config.profiles.get(name).map(|p| &p.usage)
|
||||
}
|
||||
// /// Get profile usage statistics
|
||||
// pub fn get_profile_usage(&self, name: &str) -> Option<&super::UsageStats> {
|
||||
// self.config.profiles.get(name).map(|p| &p.usage)
|
||||
// }
|
||||
|
||||
// Token management
|
||||
|
||||
@@ -188,10 +188,10 @@ impl ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a token from a profile
|
||||
pub fn get_token_from_profile(&self, profile_name: &str, service: &str) -> Option<&TokenConfig> {
|
||||
self.config.profiles.get(profile_name)?.get_token(service)
|
||||
}
|
||||
// /// Get a token from a profile
|
||||
// pub fn get_token_from_profile(&self, profile_name: &str, service: &str) -> Option<&TokenConfig> {
|
||||
// self.config.profiles.get(profile_name)?.get_token(service)
|
||||
// }
|
||||
|
||||
/// Remove a token from a profile
|
||||
pub fn remove_token_from_profile(&mut self, profile_name: &str, service: &str) -> Result<()> {
|
||||
@@ -204,20 +204,20 @@ impl ConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// List all tokens in a profile
|
||||
pub fn list_profile_tokens(&self, profile_name: &str) -> Option<Vec<&String>> {
|
||||
self.config.profiles.get(profile_name).map(|p| p.tokens.keys().collect())
|
||||
}
|
||||
// /// List all tokens in a profile
|
||||
// pub fn list_profile_tokens(&self, profile_name: &str) -> Option<Vec<&String>> {
|
||||
// self.config.profiles.get(profile_name).map(|p| p.tokens.keys().collect())
|
||||
// }
|
||||
|
||||
// Repository profile management
|
||||
|
||||
/// Get profile for repository
|
||||
pub fn get_repo_profile(&self, repo_path: &str) -> Option<&GitProfile> {
|
||||
self.config
|
||||
.repo_profiles
|
||||
.get(repo_path)
|
||||
.and_then(|name| self.config.profiles.get(name))
|
||||
}
|
||||
// /// Get profile for repository
|
||||
// pub fn get_repo_profile(&self, repo_path: &str) -> Option<&GitProfile> {
|
||||
// self.config
|
||||
// .repo_profiles
|
||||
// .get(repo_path)
|
||||
// .and_then(|name| self.config.profiles.get(name))
|
||||
// }
|
||||
|
||||
/// Set profile for repository
|
||||
pub fn set_repo_profile(&mut self, repo_path: String, profile_name: String) -> Result<()> {
|
||||
@@ -229,26 +229,26 @@ impl ConfigManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove repository profile mapping
|
||||
pub fn remove_repo_profile(&mut self, repo_path: &str) {
|
||||
self.config.repo_profiles.remove(repo_path);
|
||||
self.modified = true;
|
||||
}
|
||||
// /// Remove repository profile mapping
|
||||
// pub fn remove_repo_profile(&mut self, repo_path: &str) {
|
||||
// self.config.repo_profiles.remove(repo_path);
|
||||
// self.modified = true;
|
||||
// }
|
||||
|
||||
/// List repository profile mappings
|
||||
pub fn list_repo_profiles(&self) -> &HashMap<String, String> {
|
||||
&self.config.repo_profiles
|
||||
}
|
||||
// /// List repository profile mappings
|
||||
// pub fn list_repo_profiles(&self) -> &HashMap<String, String> {
|
||||
// &self.config.repo_profiles
|
||||
// }
|
||||
|
||||
/// Get effective profile for a repository (repo-specific -> default)
|
||||
pub fn get_effective_profile(&self, repo_path: Option<&str>) -> Option<&GitProfile> {
|
||||
if let Some(path) = repo_path {
|
||||
if let Some(profile) = self.get_repo_profile(path) {
|
||||
return Some(profile);
|
||||
}
|
||||
}
|
||||
self.default_profile()
|
||||
}
|
||||
// /// Get effective profile for a repository (repo-specific -> default)
|
||||
// pub fn get_effective_profile(&self, repo_path: Option<&str>) -> Option<&GitProfile> {
|
||||
// if let Some(path) = repo_path {
|
||||
// if let Some(profile) = self.get_repo_profile(path) {
|
||||
// return Some(profile);
|
||||
// }
|
||||
// }
|
||||
// self.default_profile()
|
||||
// }
|
||||
|
||||
/// Check and compare profile with git configuration
|
||||
pub fn check_profile_config(&self, profile_name: &str, repo: &git2::Repository) -> Result<super::ProfileComparison> {
|
||||
@@ -383,31 +383,31 @@ impl ConfigManager {
|
||||
&self.keyring
|
||||
}
|
||||
|
||||
/// Configure LLM provider with all settings
|
||||
pub fn configure_llm(&mut self, provider: String, model: Option<String>, base_url: Option<String>, api_key: Option<&str>) -> Result<()> {
|
||||
self.set_llm_provider(provider.clone());
|
||||
// /// Configure LLM provider with all settings
|
||||
// pub fn configure_llm(&mut self, provider: String, model: Option<String>, base_url: Option<String>, api_key: Option<&str>) -> Result<()> {
|
||||
// self.set_llm_provider(provider.clone());
|
||||
|
||||
if let Some(m) = model {
|
||||
self.set_llm_model(m);
|
||||
}
|
||||
// if let Some(m) = model {
|
||||
// self.set_llm_model(m);
|
||||
// }
|
||||
|
||||
self.set_llm_base_url(base_url);
|
||||
// self.set_llm_base_url(base_url);
|
||||
|
||||
if let Some(key) = api_key {
|
||||
if provider_needs_api_key(&provider) {
|
||||
self.set_api_key(key)?;
|
||||
}
|
||||
}
|
||||
// if let Some(key) = api_key {
|
||||
// if provider_needs_api_key(&provider) {
|
||||
// self.set_api_key(key)?;
|
||||
// }
|
||||
// }
|
||||
|
||||
Ok(())
|
||||
}
|
||||
// Ok(())
|
||||
// }
|
||||
|
||||
// Commit configuration
|
||||
|
||||
/// Get commit format
|
||||
pub fn commit_format(&self) -> super::CommitFormat {
|
||||
self.config.commit.format
|
||||
}
|
||||
// /// Get commit format
|
||||
// pub fn commit_format(&self) -> super::CommitFormat {
|
||||
// self.config.commit.format
|
||||
// }
|
||||
|
||||
/// Set commit format
|
||||
pub fn set_commit_format(&mut self, format: super::CommitFormat) {
|
||||
@@ -415,10 +415,10 @@ impl ConfigManager {
|
||||
self.modified = true;
|
||||
}
|
||||
|
||||
/// Check if auto-generate is enabled
|
||||
pub fn auto_generate_commits(&self) -> bool {
|
||||
self.config.commit.auto_generate
|
||||
}
|
||||
// /// Check if auto-generate is enabled
|
||||
// pub fn auto_generate_commits(&self) -> bool {
|
||||
// self.config.commit.auto_generate
|
||||
// }
|
||||
|
||||
/// Set auto-generate commits
|
||||
pub fn set_auto_generate_commits(&mut self, enabled: bool) {
|
||||
@@ -428,10 +428,10 @@ impl ConfigManager {
|
||||
|
||||
// Tag configuration
|
||||
|
||||
/// Get version prefix
|
||||
pub fn version_prefix(&self) -> &str {
|
||||
&self.config.tag.version_prefix
|
||||
}
|
||||
// /// Get version prefix
|
||||
// pub fn version_prefix(&self) -> &str {
|
||||
// &self.config.tag.version_prefix
|
||||
// }
|
||||
|
||||
/// Set version prefix
|
||||
pub fn set_version_prefix(&mut self, prefix: String) {
|
||||
@@ -441,10 +441,10 @@ impl ConfigManager {
|
||||
|
||||
// Changelog configuration
|
||||
|
||||
/// Get changelog path
|
||||
pub fn changelog_path(&self) -> &str {
|
||||
&self.config.changelog.path
|
||||
}
|
||||
// /// Get changelog path
|
||||
// pub fn changelog_path(&self) -> &str {
|
||||
// &self.config.changelog.path
|
||||
// }
|
||||
|
||||
/// Set changelog path
|
||||
pub fn set_changelog_path(&mut self, path: String) {
|
||||
@@ -454,10 +454,10 @@ impl ConfigManager {
|
||||
|
||||
// Language configuration
|
||||
|
||||
/// Get output language
|
||||
pub fn output_language(&self) -> &str {
|
||||
&self.config.language.output_language
|
||||
}
|
||||
// /// Get output language
|
||||
// pub fn output_language(&self) -> &str {
|
||||
// &self.config.language.output_language
|
||||
// }
|
||||
|
||||
/// Set output language
|
||||
pub fn set_output_language(&mut self, language: String) {
|
||||
|
||||
@@ -9,7 +9,7 @@ pub mod profile;
|
||||
|
||||
pub use profile::{
|
||||
GitProfile, TokenConfig, TokenType,
|
||||
UsageStats, ProfileComparison
|
||||
ProfileComparison
|
||||
};
|
||||
|
||||
/// Application configuration
|
||||
@@ -505,18 +505,18 @@ impl AppConfig {
|
||||
Ok(config_dir.join("quicommit").join("config.toml"))
|
||||
}
|
||||
|
||||
/// Get profile for a repository
|
||||
pub fn get_profile_for_repo(&self, repo_path: &str) -> Option<&GitProfile> {
|
||||
let profile_name = self.repo_profiles.get(repo_path)?;
|
||||
self.profiles.get(profile_name)
|
||||
}
|
||||
// /// Get profile for a repository
|
||||
// pub fn get_profile_for_repo(&self, repo_path: &str) -> Option<&GitProfile> {
|
||||
// let profile_name = self.repo_profiles.get(repo_path)?;
|
||||
// self.profiles.get(profile_name)
|
||||
// }
|
||||
|
||||
/// Set profile for a repository
|
||||
pub fn set_profile_for_repo(&mut self, repo_path: String, profile_name: String) -> Result<()> {
|
||||
if !self.profiles.contains_key(&profile_name) {
|
||||
anyhow::bail!("Profile '{}' does not exist", profile_name);
|
||||
}
|
||||
self.repo_profiles.insert(repo_path, profile_name);
|
||||
Ok(())
|
||||
}
|
||||
// /// Set profile for a repository
|
||||
// pub fn set_profile_for_repo(&mut self, repo_path: String, profile_name: String) -> Result<()> {
|
||||
// if !self.profiles.contains_key(&profile_name) {
|
||||
// anyhow::bail!("Profile '{}' does not exist", profile_name);
|
||||
// }
|
||||
// self.repo_profiles.insert(repo_path, profile_name);
|
||||
// Ok(())
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -642,12 +642,16 @@ impl GitRepo {
|
||||
name: name.to_string(),
|
||||
target: oid.to_string(),
|
||||
message: commit.message().unwrap_or("").to_string(),
|
||||
time: commit.time().seconds(),
|
||||
});
|
||||
}
|
||||
|
||||
true
|
||||
})?;
|
||||
|
||||
// Sort tags by time (newest first)
|
||||
tags.sort_by(|a, b| b.time.cmp(&a.time));
|
||||
|
||||
Ok(tags)
|
||||
}
|
||||
|
||||
@@ -832,6 +836,7 @@ pub struct TagInfo {
|
||||
pub name: String,
|
||||
pub target: String,
|
||||
pub message: String,
|
||||
pub time: i64,
|
||||
}
|
||||
|
||||
/// Repository status summary
|
||||
|
||||
Reference in New Issue
Block a user