Add staged files (so random files don't get removed)

This commit is contained in:
2026-03-03 11:16:22 +00:00
parent c0a71bc285
commit 399a72f380
5 changed files with 141 additions and 28 deletions

View File

@@ -2,19 +2,20 @@ use clap::{Parser, Subcommand};
use std::error::Error;
use std::path::PathBuf;
mod add;
mod commit;
mod end;
mod error;
mod info;
mod init;
mod step;
mod utils;
mod info;
const TOUR_DIR: &str = "./.tour";
const SESSION_PATH: &str = "./.tour/session";
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(author, version, about, long_about = None, disable_help_subcommand = true)]
struct Args {
#[command(subcommand)]
command: Option<Commands>,
@@ -25,6 +26,11 @@ enum Commands {
// Create a new tour
Init,
// Stage files for the next commit
Add {
files: Vec<PathBuf>,
},
// Add steps to the tour
Commit {
files: Vec<PathBuf>,
@@ -61,12 +67,40 @@ enum Commands {
Start,
Info,
// Show help
Help,
}
fn help() {
println!(
"\
\x1b[1mtour\x1b[0m — create and navigate code tutorials as a series of snapshots
\x1b[1mAUTHOR WORKFLOW\x1b[0m
tour init Set up a new tour in the current directory
tour add <files...> Stage files for the next commit
tour commit [-m <msg>] Commit staged files as a new step
tour commit <files...> -m <msg> Stage and commit files in one step
tour end -m <msg> Finalise the tour
\x1b[1mREADER WORKFLOW\x1b[0m
tour start Load the first step
tour next [n] Advance n steps (default 1)
tour prev [n] Go back n steps (default 1)
tour step <n> Jump to step n
\x1b[1mOTHER\x1b[0m
tour info Show tour metadata
tour help Show this help message"
);
}
fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
match args.command {
Some(Commands::Init) => crate::init::init()?,
Some(Commands::Add { files }) => crate::add::add(files)?,
Some(Commands::Commit { files, message }) => crate::commit::commit(files, message)?,
Some(Commands::End { message }) => crate::end::end(message)?,
Some(Commands::Next { n }) => crate::step::next(n)?,
@@ -74,7 +108,7 @@ fn main() -> Result<(), Box<dyn Error>> {
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"),
Some(Commands::Help) | None => help(),
}
Ok(())
}