#![allow(clippy::exit)]
use crate::server::git::serve_git;
use crate::utils::library::find_library_path;
use clap::Parser;
use std::path::Path;
use tracing;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[arg(short, long, default_value_t = String::from(".").to_owned())]
library_path: String,
#[command(subcommand)]
subcommands: Subcommands,
}
#[derive(Clone, clap::Subcommand)]
enum Subcommands {
Git {
#[arg(short, long, default_value_t = 8080)]
port: u16,
},
}
fn init_tracing() {
tracing_subscriber::fmt::init();
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}
}
pub fn run() -> std::io::Result<()> {
init_tracing();
tracing::debug!("Starting application");
let cli = Cli::parse();
let library_path_wd = Path::new(&cli.library_path);
let Ok(library_path) = find_library_path(library_path_wd) else {
tracing::error!(
"error: could not find `.stelae` folder in `{}` or any parent directory",
&cli.library_path
);
std::process::exit(1);
};
match cli.subcommands {
Subcommands::Git { port } => serve_git(&cli.library_path, library_path, port),
}
}