Usability: - Command aliases (n, p, s, ls, st) and positional step counts for next/prev - next/prev clamp at the tour ends instead of erroring - Color only when stdout is a TTY and NO_COLOR is unset (new style.rs) - reset asks for confirmation; --force required when non-interactive - IO errors carry operation context; friendlier not-started/no-steps errors - list marks the current step; consistent lowercase verb output - Handle SIGPIPE like other CLI tools instead of panicking when piped Efficiency: - Carry-forward hardlinks unchanged files between steps (copy fallback), so a step only costs disk for its changes; copy_path unlinks before overwriting so overlays can't write through a link - Navigation installs only files that differ (inode/size/byte compare) instead of two full-tree copies through a temp dir - Change report reads only changed files; LCS diff trims common prefix/suffix; path validation canonicalizes anchors once Adds 10 integration tests (rm carry-forward, reset --force, clamping, aliases, binary files, piped output, inode sharing, old-format compat, unchanged-file mtimes). Old tours need no migration. Co-Authored-By: Claude Fable 5 <[email protected]>
46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
use crate::error::TourError;
|
|
use crate::style::{red, reset};
|
|
use crate::utils::require_tour;
|
|
use std::collections::HashSet;
|
|
use std::fs::{self, OpenOptions};
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
|
|
pub const REMOVED_PATH: &str = "./.tour/removed";
|
|
|
|
pub fn rm(files: Vec<PathBuf>) -> Result<(), TourError> {
|
|
require_tour()?;
|
|
|
|
let existing = get_removed()?;
|
|
let existing_set: HashSet<PathBuf> = existing.into_iter().collect();
|
|
|
|
let mut removed_file = OpenOptions::new()
|
|
.append(true)
|
|
.create(true)
|
|
.open(REMOVED_PATH)?;
|
|
|
|
for file in &files {
|
|
if existing_set.contains(file) {
|
|
println!("already marked for removal: {}", file.display());
|
|
} else {
|
|
writeln!(removed_file, "{}", file.display())?;
|
|
println!("{}marked for removal:{} {}", red(), reset(), file.display());
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub fn get_removed() -> Result<Vec<PathBuf>, std::io::Error> {
|
|
let content = fs::read_to_string(REMOVED_PATH).unwrap_or_default();
|
|
Ok(content
|
|
.lines()
|
|
.filter(|l| !l.is_empty())
|
|
.map(PathBuf::from)
|
|
.collect())
|
|
}
|
|
|
|
pub fn clear_removed() -> Result<(), std::io::Error> {
|
|
fs::write(REMOVED_PATH, "")
|
|
}
|