feat: argparse and dry-run.

This commit is contained in:
2026-01-04 01:46:39 +08:00
parent 21e0e96841
commit 5ce56bda36
10 changed files with 656 additions and 90 deletions
+48
View File
@@ -0,0 +1,48 @@
use std::path::Path;
pub struct ShellScript {
lines: Vec<String>,
}
impl ShellScript {
pub fn new() -> Self {
Self {
lines: Vec::new(),
}
}
pub fn add_comment(&mut self, comment: &str) {
self.lines.push(format!("# {}", comment));
}
pub fn add_variable(&mut self, name: &str, value: &Path) {
let escaped = escape_path(value);
self.lines.push(format!("{}=\"{}\"", name, escaped));
}
pub fn add_command(&mut self, command: &str) {
self.lines.push(command.to_string());
}
pub fn add_empty_line(&mut self) {
self.lines.push(String::new());
}
pub fn output(&self) -> String {
self.lines.join("\n")
}
}
fn escape_path(path: &Path) -> String {
path.display().to_string().replace('"', r#"\""#).replace('$', r#"\$"#)
}
pub fn print_shell_script_header() {
println!("#!/bin/sh");
println!("# Generated by bilibili-merge dry-run mode");
println!();
}
pub fn print_shell_script(script: &ShellScript) {
println!("{}", script.output());
}