upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/main.rs
blob: f07203a93ab86b31a6e460940e02e9813d6323ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#![cfg_attr(not(test), warn(clippy::pedantic))]
#![allow(clippy::large_futures)]
#![cfg_attr(not(test), warn(clippy::expect_used))]

use anyhow::Result;
use clap::Parser;
use cli::{AccountCommands, CUSTOMISE_TEMPLATE, Cli, Commands};

mod cli;
use ngit::{cli_interactor, client, git, git_events, login, repo_ref};

mod sub_commands;

#[tokio::main]
async fn main() -> Result<()> {
    let cli = Cli::parse();

    if cli.customize {
        print!("{CUSTOMISE_TEMPLATE}");
        std::process::exit(0); // Exit the program
    }

    if let Some(command) = &cli.command {
        match command {
            Commands::Account(args) => match &args.account_command {
                AccountCommands::Login(sub_args) => {
                    sub_commands::login::launch(&cli, sub_args).await
                }
                AccountCommands::Logout => sub_commands::logout::launch().await,
                AccountCommands::ExportKeys => sub_commands::export_keys::launch().await,
            },
            Commands::Init(args) => sub_commands::init::launch(&cli, args).await,
            Commands::List => sub_commands::list::launch().await,
            Commands::Send(args) => sub_commands::send::launch(&cli, args, false).await,
            Commands::Sync(args) => sub_commands::sync::launch(args).await,
        }
    } else {
        // Handle the case where no command is provided
        eprintln!("Error: A command must be provided. Use '--help' for more information.");
        std::process::exit(1);
    }
}