git-next/crates/cli/src/main.rs

75 lines
1.7 KiB
Rust
Raw Normal View History

//
mod alerts;
mod file_watcher;
mod forge;
mod init;
mod repo;
mod server;
#[cfg(feature = "tui")]
mod tui;
2024-05-14 07:58:28 +01:00
#[cfg(test)]
mod tests;
mod webhook;
2024-05-14 07:58:28 +01:00
use git_next_core::git;
2024-04-28 08:05:09 +01:00
use std::path::PathBuf;
use anyhow::Result;
2024-04-06 18:26:08 +01:00
use clap::Parser;
2024-04-28 08:05:09 +01:00
use kxio::{fs, network::Network};
2024-04-06 18:26:08 +01:00
#[derive(Parser, Debug)]
#[clap(version = clap::crate_version!(), author = clap::crate_authors!(), about = clap::crate_description!())]
struct Commands {
#[clap(subcommand)]
command: Command,
}
#[derive(Parser, Debug)]
enum Command {
Init,
#[clap(subcommand)]
Server(Server),
}
#[derive(Parser, Debug)]
enum Server {
Init,
Start {
/// Display a UI (experimental)
#[cfg(feature = "tui")]
#[arg(long, required = false)]
ui: bool,
},
2024-04-06 18:26:08 +01:00
}
fn main() -> Result<()> {
2024-04-28 08:05:09 +01:00
let fs = fs::new(PathBuf::default());
2024-04-09 10:44:01 +01:00
let net = Network::new_real();
let repository_factory = git::repository::factory::real();
2024-04-06 18:26:08 +01:00
let commands = Commands::parse();
match commands.command {
Command::Init => {
init::run(&fs)?;
2024-04-06 18:26:08 +01:00
}
Command::Server(server) => match server {
Server::Init => {
server::init(&fs)?;
2024-04-06 18:26:08 +01:00
}
#[cfg(not(feature = "tui"))]
Server::Start {} => {
let sleep_duration = std::time::Duration::from_secs(10);
server::start(false, fs, net, repository_factory, sleep_duration)?;
}
#[cfg(feature = "tui")]
Server::Start { ui } => {
let sleep_duration = std::time::Duration::from_secs(10);
server::start(ui, fs, net, repository_factory, sleep_duration)?;
2024-04-06 18:26:08 +01:00
}
},
}
Ok(())
2024-04-06 17:39:56 +01:00
}