Create file directorys in init
This commit is contained in:
25
src/init.rs
Normal file
25
src/init.rs
Normal 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(())
|
||||
}
|
||||
16
src/main.rs
16
src/main.rs
@@ -2,6 +2,11 @@ use clap::{Parser, Subcommand};
|
||||
use std::error::Error;
|
||||
use std::path::PathBuf;
|
||||
|
||||
mod init;
|
||||
mod utils;
|
||||
|
||||
const TOUR_DIR: &str = "./.tour";
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
@@ -13,8 +18,10 @@ struct Args {
|
||||
enum Commands {
|
||||
// Create a new tour
|
||||
Init {
|
||||
#[arg(short, long, value_name = "MESSAGE")]
|
||||
message: Option<String>,
|
||||
#[arg(value_name = "FILES")]
|
||||
files: Vec<PathBuf>,
|
||||
#[arg(short, value_name = "MESSAGE")]
|
||||
message: String,
|
||||
},
|
||||
// Add steps to the tour
|
||||
Commit {
|
||||
@@ -43,6 +50,9 @@ enum Commands {
|
||||
|
||||
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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user