adding important subcommands

This commit is contained in:
2026-03-02 21:55:37 +00:00
parent 1dea592fb2
commit c0a71bc285
4 changed files with 217 additions and 30 deletions

View File

@@ -4,13 +4,14 @@ use std::path::PathBuf;
mod commit;
mod end;
mod error;
mod init;
mod next;
mod prev;
mod step;
mod utils;
mod info;
const TOUR_DIR: &str = "./.tour";
const DEFAULT_SESSION: &str = "./.tour/session";
const SESSION_PATH: &str = "./.tour/session";
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
@@ -22,12 +23,8 @@ struct Args {
#[derive(Subcommand)]
enum Commands {
// Create a new tour
Init {
#[arg(value_name = "FILES")]
files: Vec<PathBuf>,
#[arg(short, value_name = "MESSAGE")]
message: String,
},
Init,
// Add steps to the tour
Commit {
files: Vec<PathBuf>,
@@ -35,6 +32,7 @@ enum Commands {
#[arg(short, long, value_name = "MESSAGE")]
message: String,
},
// Finish the tour
End {
#[arg(short, long, value_name = "MESSAGE")]
@@ -46,21 +44,36 @@ enum Commands {
#[arg(short, value_name = "NUM STEPS")]
n: Option<i32>,
},
// Go to previous step of tour
Prev {
#[arg(short, value_name = "NUM STEPS")]
n: Option<i32>,
},
// Go to a specific step of tour
Step {
#[arg(value_name = "STEP")]
n: i32,
},
// Go to beginning of tour
Start,
Info,
}
fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
match args.command {
Some(Commands::Init { files, message }) => crate::init::init(files, message)?,
Some(Commands::Init) => crate::init::init()?,
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)?,
Some(Commands::Next { n }) => crate::step::next(n)?,
Some(Commands::Prev { n }) => crate::step::prev(n)?,
Some(Commands::Step { n }) => crate::step::step_n(n)?,
Some(Commands::Start) => crate::step::step_n(0)?,
Some(Commands::Info) => crate::info::info()?,
_ => println!("command not found"),
}
Ok(())