Thunderstore CLI and Northstar mod dev helper
use clap::{Parser, Subcommand};
use log::LevelFilter;
use simplelog::{Config, TermLogger, TerminalMode};

mod core;

#[derive(Parser)]
struct Cli {
    #[clap(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    New {
        #[clap(short, long)]
        author: Option<String>,
        name: String,
        #[clap(long)]
        no_vcs: bool,
    },

    Init {
        #[clap(short, long)]
        author: Option<String>,
        name: String,
    },

    Init {
        name: String,
        #[clap(long)]
        no_vcs: bool,
    },
}

#[tokio::main]
async fn main() {
    TermLogger::init(
        LevelFilter::Info,
        Config::default(),
        TerminalMode::Mixed,
        simplelog::ColorChoice::Auto,
    )
    .expect("Unable to init logger");

    let cli = Cli::parse();

    //handle subcommands
    match cli.command {
        Commands::New {
            author,
            name,
            no_vcs,
        } => {
            let author = if let Some(a) = author {
                a
            } else {
                //TODO: Attempt to load from config, or else fail
                String::new()
            };
            core::create(author, name, no_vcs);
        }
        Commands::Init { name } => {
            core::init(name);
        }
        Commands::Init {
            author,
            name,
            no_vcs,
        } => {
            let author = if let Some(a) = author {
                a
            } else {
                //TODO: Attempt to load from config, or else fail
                String::new()
            };
            core::init(author, name, no_vcs);
        }
    }
}