pinakes/crates/pinakes-tui/src/main.rs
NotAShelf 66861b8a20
pinakes-tui: add book management view and api key authentication
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I20f205d9e06a93a89e8f4433ed6f80576a6a6964
2026-03-08 00:43:31 +03:00

61 lines
1.4 KiB
Rust

use anyhow::Result;
use clap::Parser;
use tracing_subscriber::EnvFilter;
mod app;
mod client;
mod event;
mod input;
mod ui;
/// Pinakes terminal UI client
#[derive(Parser)]
#[command(name = "pinakes-tui", version, about)]
struct Cli {
/// Server URL to connect to
#[arg(
short,
long,
env = "PINAKES_SERVER_URL",
default_value = "http://localhost:3000"
)]
server: String,
/// API key for bearer token authentication
#[arg(long, env = "PINAKES_API_KEY")]
api_key: Option<String>,
/// Set log level (trace, debug, info, warn, error)
#[arg(long, default_value = "warn")]
log_level: String,
/// Log to file instead of stderr (avoids corrupting TUI display)
#[arg(long)]
log_file: Option<std::path::PathBuf>,
}
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
// Initialize logging - for TUI, must log to file to avoid corrupting the
// display
let env_filter = EnvFilter::try_new(&cli.log_level)
.unwrap_or_else(|_| EnvFilter::new("warn"));
if let Some(log_path) = &cli.log_file {
let file = std::fs::File::create(log_path)?;
tracing_subscriber::fmt()
.with_env_filter(env_filter)
.with_writer(file)
.with_ansi(false)
.init();
} else {
// When no log file specified, suppress all output to avoid TUI corruption
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::new("off"))
.init();
}
app::run(&cli.server, cli.api_key.as_deref()).await
}