Adding all commands and boilerplate

This commit is contained in:
2026-02-23 14:46:19 +00:00
parent 593ad42d3b
commit 26eccecc7c
6 changed files with 49 additions and 18 deletions

24
src/commit.rs Normal file
View File

@@ -0,0 +1,24 @@
use crate::TOUR_DIR;
use std::fs;
use std::io::Write;
use std::path::PathBuf;
pub fn commit(files: Vec<PathBuf>, message: String) -> Result<(), std::io::Error> {
// let files = files.iter().map(|p| p.as_ref()).collect();
//
// let dir = std::fs::read_dir(format!("{}/steps", TOUR_DIR))?;
//
// // USE /steps to find number of next step
// // let step_number =
//
// fs::create_dir_all(format!("{}/{}", TOUR_DIR, "steps/0/files"))?;
//
// // Copy files listed by command to step 0
// let dest = format!("{}/steps/0/files/", TOUR_DIR);
// crate::utils::copy_files(files, dest.as_ref())?;
//
// // Copy message
// let mut message_file = fs::File::create(format!("{}/steps/{}/message", TOUR_DIR, step_number))?;
// write!(message_file, "{}", message)?;
Ok(())
}

3
src/end.rs Normal file
View File

@@ -0,0 +1,3 @@
pub fn end(message: String) -> Result<(), std::io::Error> {
Ok(())
}

View File

@@ -12,23 +12,14 @@ use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
pub fn init(files: Vec<PathBuf>, message: String) -> Result<(), std::io::Error> { pub fn init(files: Vec<PathBuf>, message: String) -> Result<(), std::io::Error> {
// Convert PathBuf to &Path // // Convert PathBuf to &Path
let files = files.iter().map(|p| p.as_path()).collect(); // let files = files.iter().map(|p| p.as_path()).collect();
//
// Check TOUR_DIR exists (it shouldn't because user calls init) // // Check TOUR_DIR exists (it shouldn't because user calls init)
if fs::exists(TOUR_DIR)? { // if fs::exists(TOUR_DIR)? {
panic!("{} folder exists", TOUR_DIR); // panic!("{} folder exists", TOUR_DIR);
} // }
// Create dir recursively // // Create dir recursively
fs::create_dir_all(format!("{}/{}", TOUR_DIR, "steps/0/files"))?;
// Copy files listed by command to step 0
let dest = format!("{}/steps/0/files/", TOUR_DIR);
copy_files(files, dest.as_ref())?;
// Copy message to step 0
let mut message_file = File::create("./.tour/steps/0/message")?;
write!(message_file, "{}", message)?;
Ok(()) Ok(())
} }

View File

@@ -3,10 +3,14 @@ use std::error::Error;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
mod commit; mod commit;
mod end;
mod init; mod init;
mod next;
mod prev;
mod utils; mod utils;
const TOUR_DIR: &str = "./.tour"; const TOUR_DIR: &str = "./.tour";
const DEFAULT_SESSION: &str = "./.tour/session";
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
@@ -34,7 +38,7 @@ enum Commands {
// Finish the tour // Finish the tour
End { End {
#[arg(short, long, value_name = "MESSAGE")] #[arg(short, long, value_name = "MESSAGE")]
message: Option<String>, message: String,
}, },
// Go to next step of tour // Go to next step of tour
@@ -54,6 +58,9 @@ fn main() -> Result<(), Box<dyn Error>> {
match args.command { match args.command {
Some(Commands::Init { files, message }) => crate::init::init(files, message)?, Some(Commands::Init { files, message }) => crate::init::init(files, message)?,
Some(Commands::Commit { files, message }) => crate::commit::commit(files, message)?, Some(Commands::Commit { files, message }) => crate::commit::commit(files, message)?,
Some(Commands::End { message }) => crate::end::end(message)?,
Some(Commands::Next { n }) => crate::next::next(n)?,
Some(Commands::Prev { n }) => crate::prev::prev(n)?,
_ => println!("command not found"), _ => println!("command not found"),
} }
Ok(()) Ok(())

3
src/next.rs Normal file
View File

@@ -0,0 +1,3 @@
pub fn next(n: Option<i32>) -> Result<(), std::io::Error> {
Ok(())
}

3
src/prev.rs Normal file
View File

@@ -0,0 +1,3 @@
pub fn prev(n: Option<i32>) -> Result<(), std::io::Error> {
Ok(())
}