Fix bugs and improve robustness across the codebase
- Fix staged files being silently cleared when commit uses inline files - Refactor step navigation to use direct go_to_step instead of fragile delta math - Change step numbers from i32 to u32 (reject negative values at parse time) - Add tour rm command to mark files for removal during carry-forward - Add tour reset command to clear session and remove tracked files - Consolidate duplicate recursive copy functions into shared copy_tree in utils - Validate step directories are sequential (detect corruption) - Detect binary files in diffs instead of showing garbage - Use /// doc comments on enum variants so clap generates proper help text - Remove custom Help subcommand in favor of clap's built-in --help - Add CorruptedTour error variant for integrity checks Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
+41
-10
@@ -1,20 +1,51 @@
|
||||
// Create a .tour folder
|
||||
// Create directory ./.tour/steps that stores tutorial steps
|
||||
// Create file ./.tour/session that logs sessions information
|
||||
|
||||
use crate::error::TourError;
|
||||
use crate::TOUR_DIR;
|
||||
use std::fs::DirBuilder;
|
||||
use std::path::PathBuf;
|
||||
use std::fs::{self, DirBuilder, OpenOptions};
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
// Creates the directory for tour
|
||||
pub fn init() -> Result<(), std::io::Error> {
|
||||
pub fn init() -> Result<(), TourError> {
|
||||
let tour_dir = PathBuf::from(TOUR_DIR);
|
||||
|
||||
if tour_dir.exists() {
|
||||
return Err(TourError::TourAlreadyExists);
|
||||
}
|
||||
|
||||
DirBuilder::new()
|
||||
.recursive(true)
|
||||
.create(tour_dir.join("steps"))?;
|
||||
|
||||
std::fs::File::create(tour_dir.join("session"))?;
|
||||
fs::File::create(tour_dir.join("session"))?;
|
||||
|
||||
crate::info::set_info()
|
||||
crate::info::set_info()?;
|
||||
update_gitignore()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_gitignore() -> Result<(), std::io::Error> {
|
||||
let gitignore = Path::new(".gitignore");
|
||||
let entries = [".tour/session", ".tour/staged", ".tour/removed"];
|
||||
|
||||
let existing = fs::read_to_string(gitignore).unwrap_or_default();
|
||||
let mut to_add = Vec::new();
|
||||
for entry in &entries {
|
||||
if !existing.lines().any(|l| l.trim() == *entry) {
|
||||
to_add.push(*entry);
|
||||
}
|
||||
}
|
||||
|
||||
if !to_add.is_empty() {
|
||||
let mut file = OpenOptions::new()
|
||||
.append(true)
|
||||
.create(true)
|
||||
.open(gitignore)?;
|
||||
if !existing.is_empty() && !existing.ends_with('\n') {
|
||||
writeln!(file)?;
|
||||
}
|
||||
for entry in to_add {
|
||||
writeln!(file, "{}", entry)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user