Skip to content
#![warn(clippy::pedantic)]

use clap::{Parser, Subcommand};

mod actions;
mod remote;
mod show;
mod test;

#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Cli {
    /// url to the fig instance
    #[arg(long, env = "FIG_URL")]
    url: String,

    #[command(subcommand)]
    command: Option<Commands>,
}

#[derive(Subcommand)]
enum Commands {
    /// Shows the tree of Fig
    Show {},

    /// Repo Actions
    Repo {
        #[command(subcommand)]
        command: Option<RepoCommands>,
    },

    /// only for test purposes
    Test {},

    /// show example tree
    Example {},
}

#[derive(Subcommand)]
enum RepoCommands {
    /// Clones all repositories
    Clone {},
}

fn command_to_action(command: Option<RepoCommands>) -> Option<actions::Action> {
    match command {
        Some(RepoCommands::Clone {}) => Some(actions::Action::Clone),
        _ => None,
    }
}

#[tokio::main]
async fn main() {
    let commands = Cli::parse();

    match commands.command {
        Some(Commands::Show {}) => {
            show::run(&commands.url).await;
        }
        Some(Commands::Test {}) => {
            test::run(&commands.url).await;
        }
        Some(Commands::Example {}) => {
            remote::example_tree();
        }
        Some(Commands::Repo { command }) => {
            // let user choose repos coming back from the remote
            let repos = 
            actions::action(command_to_action(command)).await;
        }
        _ => {
            #[cfg(not(feature = "testing"))]
            show::run(&commands.url).await;

            #[cfg(feature = "testing")]
            test::run(&commands.url).await;
        }
    }
}