rvcs 0.1.0

A rusty version control system.
Documentation
use clap::{App, Arg, SubCommand};
use rvcs_lib::{
    add::add,
    branch::{create_branch, delete_branch, goto_branch, list_branches, merge},
    commit::{commit, pull, log, reset},
    init::init_repo,
};

use std::io;

fn main() -> io::Result<()> {

    if cfg!(windows) {
        panic!("This program is not intended to run on Windows, consider switching to a decent operating system.");
    }

    let matches = App::new("rcvs")
        .version(env!("CARGO_PKG_VERSION"))
        .author(env!("CARGO_PKG_AUTHORS"))
        .about("A rusty version control system.")
        .subcommand(SubCommand::with_name("init").about("Initializes a new repository."))
        .subcommand(
            SubCommand::with_name("add")
            .arg(
                Arg::with_name("file")
                .required(true)
                .index(1)
                .takes_value(true)
                .help("The file to add to the index."),
                )
            .about("Adds a file to the index."),
            )
        .subcommand(
            SubCommand::with_name("commit")
            .subcommand(
                SubCommand::with_name("log")
                .arg(
                    Arg::with_name("details")
                    .short("d")
                    .long("details")
                    .help("Specifies to show detailed commit."),
                    )
                .about("Lists the repository commits."),
                )
            .subcommand(
                SubCommand::with_name("reset")
                .arg(
                    Arg::with_name("commit_hash")
                    .required(true)
                    .index(1)
                    .takes_value(true)
                    .help("The commit hash to reset to.")
                    )
                .arg(
                    Arg::with_name("hard")
                    .long("HARD")
                    .help("Specifies to delete the upper commits.")
                    )
                .about("Resets to the specified commit.")
                )
            .subcommand(
                SubCommand::with_name("pull")
                .arg(
                    Arg::with_name("commit_hash")
                        .required(true)
                        .index(1)
                        .takes_value(true)
                        .help("The commit hash to get.")
                    )
                       )
            .arg(
                Arg::with_name("message")
                .short("m")
                .long("message")
                .takes_value(true)
                .help("The commit message."),
                )
            .arg(
                Arg::with_name("body")
                .short("b")
                .long("body")
                .takes_value(true)
                .help("The commit description."),
                )
            .about("Commits the changes in the index."),
            )
                .subcommand(
                    SubCommand::with_name("log")
                    .arg(
                        Arg::with_name("details")
                        .short("d")
                        .long("details")
                        .help("Specifies to show detailed commit."),
                        )
                    .about("Lists the repository commits."),
                    )
                .subcommand(
                    SubCommand::with_name("branch")
                    .subcommand(
                        SubCommand::with_name("show").about("Lists the current repository branches."),
                        )
                    .subcommand(
                        SubCommand::with_name("delete")
                        .arg(
                            Arg::with_name("name")
                            .required(true)
                            .index(1)
                            .help("The branch name."),
                            )
                        .about("Deletes a branch."),
                        )
                    .subcommand(
                        SubCommand::with_name("create")
                        .arg(
                            Arg::with_name("name")
                            .required(true)
                            .index(1)
                            .help("The branch name."),
                            )
                        .about("Creates a new branch."),
                        )
                    .subcommand(
                        SubCommand::with_name("goto")
                        .arg(
                            Arg::with_name("name")
                            .required(true)
                            .index(1)
                            .help("The branch name."),
                            )
                        .about("Switches to a new branch."),
                        )
                    .subcommand(
                        SubCommand::with_name("merge")
                        .arg(
                            Arg::with_name("upcoming")
                            .required(true)
                            .index(1)
                            .help("The branch to merge in the current branch."),
                            )
                        .about("Merges a branch in the current branch"),
                        )
                    .about("Branch manipulation command."),
                    )
                        .get_matches();

    if let Some(_) = matches.subcommand_matches("init") {
        init_repo()?;
    } else if let Some(m) = matches.subcommand_matches("add") {
        add(m.value_of("file").unwrap())?;
    } else if let Some(m) = matches.subcommand_matches("commit") {
        if let Some(m) = m.subcommand_matches("log") {
            log(m.is_present("details"))?;
        } else if let Some(m) = m.subcommand_matches("reset") {
            reset(m.value_of("commit_hash").unwrap(), m.is_present("hard"))?;
        } else if let Some(m) = m.subcommand_matches("pull") {
            pull(m.value_of("commit_hash").unwrap())?;
        } else {
            commit(
                m.value_of("message").unwrap_or("No message specified"),
                m.value_of("body").unwrap_or(""),
                )?;
        }
    } else if let Some(m) = matches.subcommand_matches("branch") {
        if let Some(_) = m.subcommand_matches("show") {
            list_branches()?;
        } else if let Some(sub) = m.subcommand_matches("create") {
            create_branch(sub.value_of("name").unwrap())?;
        } else if let Some(sub) = m.subcommand_matches("delete") {
            delete_branch(sub.value_of("name").unwrap())?;
        } else if let Some(sub) = m.subcommand_matches("goto") {
            goto_branch(sub.value_of("name").unwrap())?;
        } else if let Some(sub) = m.subcommand_matches("merge") {
            merge(sub.value_of("upcoming").unwrap())?;
        }
    }

    Ok(())
}