Compare commits
5 Commits
7aa3ca651e
...
5093303e8d
| Author | SHA1 | Date | |
|---|---|---|---|
| 5093303e8d | |||
| 32dcb47e3c | |||
| 8b3dc3c327 | |||
| 26eccecc7c | |||
| 593ad42d3b |
24
src/commit.rs
Normal file
24
src/commit.rs
Normal 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
3
src/end.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub fn end(message: String) -> Result<(), std::io::Error> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
25
src/init.rs
25
src/init.rs
@@ -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(())
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/main.rs
15
src/main.rs
@@ -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
4
src/next.rs
Normal 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
4
src/prev.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
pub fn prev(n: Option<i32>) -> Result<(), std::io::Error> {
|
||||||
|
let n = n.unwrap_or(1);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -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))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user