Compare commits

...

2 Commits

Author SHA1 Message Date
efa297a07a Create file directorys in init 2026-02-18 17:10:13 +00:00
39f47ef716 Add commands and options 2026-02-18 13:44:30 +00:00
4 changed files with 136 additions and 4 deletions

54
Cargo.lock generated
View File

@@ -59,6 +59,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5caf74d17c3aec5495110c34cc3f78644bfa89af6c8993ed4de2790e49b6499"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
@@ -73,6 +74,18 @@ dependencies = [
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "1.0.0"
@@ -85,6 +98,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
@@ -97,12 +116,41 @@ version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4"
dependencies = [
"proc-macro2",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3df424c70518695237746f84cede799c9c58fcb37450d7b23716568cc8bc69cb"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tour"
version = "0.1.0"
@@ -110,6 +158,12 @@ dependencies = [
"clap",
]
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "utf8parse"
version = "0.2.2"

View File

@@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"
[dependencies]
clap = "4.5.59"
clap = { version = "4.5.59", features = ["derive"] }

25
src/init.rs Normal file
View File

@@ -0,0 +1,25 @@
// Create a .tour folder
// Populate with tour/steps/0/message
// Populate with tour/steps/0/files/file1
// Populate with tour/steps/0/files/file2
use crate::TOUR_DIR;
use std::fs;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
pub fn init(files: Vec<PathBuf>, message: String) -> Result<(), std::io::Error> {
if fs::exists(TOUR_DIR).is_ok() {
panic!("{} folder exists", TOUR_DIR);
}
fs::create_dir_all(format!("{}/{}", TOUR_DIR, "steps/0/files"))?;
let dest = format!("{}/steps/0/files/", TOUR_DIR);
let mut message_file = File::create("./.tour/steps/0/message")?;
write!(message_file, "{}", message)?;
Ok(())
}

View File

@@ -1,5 +1,58 @@
use clap::Parser;
use clap::{Parser, Subcommand};
use std::error::Error;
use std::path::PathBuf;
fn main() {
println!("Hello, world!");
mod init;
mod utils;
const TOUR_DIR: &str = "./.tour";
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Args {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
// Create a new tour
Init {
#[arg(value_name = "FILES")]
files: Vec<PathBuf>,
#[arg(short, value_name = "MESSAGE")]
message: String,
},
// Add steps to the tour
Commit {
files: Vec<PathBuf>,
#[arg(short, long, value_name = "MESSAGE")]
message: Option<String>,
},
// Finish the tour
End {
#[arg(short, long, value_name = "MESSAGE")]
message: Option<String>,
},
// Go to next step of tour
Next {
#[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>,
},
}
fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
match args.command {
Some(Commands::Init { files, message }) => crate::init::init(files, message)?,
_ => println!("command not found"),
}
Ok(())
}