⬆️ chore(Cargo.toml):升级版本号至0.1.7
♻️ refactor(changelog.rs):移除prepend参数,改为自动前置到现有changelog ♻️ refactor(formatter.rs):移除未使用的日期和格式化函数 ♻️ refactor(validators.rs):移除未使用的SSH密钥验证功能
This commit is contained in:
@@ -39,10 +39,6 @@ pub struct ChangelogCommand {
|
||||
#[arg(short, long)]
|
||||
generate: bool,
|
||||
|
||||
/// Prepend to existing changelog
|
||||
#[arg(short, long)]
|
||||
prepend: bool,
|
||||
|
||||
/// Include commit hashes
|
||||
#[arg(long)]
|
||||
include_hashes: bool,
|
||||
@@ -162,13 +158,34 @@ impl ChangelogCommand {
|
||||
}
|
||||
}
|
||||
|
||||
// Write to file
|
||||
if self.prepend && output_path.exists() {
|
||||
// Write to file (always prepend to preserve history)
|
||||
if output_path.exists() {
|
||||
let existing = std::fs::read_to_string(&output_path)?;
|
||||
let new_content = format!("{}\n{}", changelog, existing);
|
||||
let new_content = if existing.is_empty() {
|
||||
format!("# Changelog\n\n{}", changelog)
|
||||
} else {
|
||||
let lines: Vec<&str> = existing.lines().collect();
|
||||
let mut header_end = 0;
|
||||
|
||||
for (i, line) in lines.iter().enumerate() {
|
||||
if i == 0 && line.starts_with('#') {
|
||||
header_end = i + 1;
|
||||
} else if line.trim().is_empty() {
|
||||
header_end = i + 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let header = lines[..header_end].join("\n");
|
||||
let rest = lines[header_end..].join("\n");
|
||||
|
||||
format!("{}\n{}\n{}", header, changelog, rest)
|
||||
};
|
||||
std::fs::write(&output_path, new_content)?;
|
||||
} else {
|
||||
std::fs::write(&output_path, changelog)?;
|
||||
let content = format!("# Changelog\n\n{}", changelog);
|
||||
std::fs::write(&output_path, content)?;
|
||||
}
|
||||
|
||||
println!("{} {:?}", messages.changelog_written(), output_path);
|
||||
|
||||
Reference in New Issue
Block a user