Compare commits

...

5 Commits

Author SHA1 Message Date
5093303e8d adding future functions 2026-02-23 15:12:43 +00:00
32dcb47e3c remove unused imports 2026-02-23 15:12:37 +00:00
8b3dc3c327 unwrapping presents 2026-02-23 15:12:16 +00:00
26eccecc7c Adding all commands and boilerplate 2026-02-23 14:46:19 +00:00
593ad42d3b Non optional message & commit command 2026-02-23 14:30:36 +00:00
7 changed files with 60 additions and 20 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

@@ -1,11 +1,16 @@
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use std::error::Error; use std::error::Error;
use std::path::{Path, PathBuf}; use std::path::PathBuf;
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)]
@@ -28,12 +33,12 @@ enum Commands {
files: Vec<PathBuf>, files: Vec<PathBuf>,
#[arg(short, long, value_name = "MESSAGE")] #[arg(short, long, value_name = "MESSAGE")]
message: Option<String>, message: String,
}, },
// 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
@@ -52,6 +57,10 @@ fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse(); let args = Args::parse();
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::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(())

4
src/next.rs Normal file
View File

@@ -0,0 +1,4 @@
pub fn next(n: Option<i32>) -> Result<(), std::io::Error> {
let n = n.unwrap_or(1);
Ok(())
}

4
src/prev.rs Normal file
View File

@@ -0,0 +1,4 @@
pub fn prev(n: Option<i32>) -> Result<(), std::io::Error> {
let n = n.unwrap_or(1);
Ok(())
}

View File

@@ -17,3 +17,8 @@ pub fn copy_files(files: Vec<&Path>, dest_dir: &Path) -> Result<(), io::Error> {
} }
Ok(()) Ok(())
} }
pub fn session_step(session_file: &Path) -> Result<u32, Box<dyn std::error::Error>> {
// Read ./.tour/session to find what step user is currently looking at
Ok((0))
}