ncadmin/src/main.rs

54 lines
1.2 KiB
Rust

mod api;
mod state;
mod ui;
use anyhow::Result;
use api::Api;
use clap::Parser;
/// A tui for administrating nerdcult.net
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// The base URL of the API
#[arg(short, long, default_value = "https://api.nerdcult.net")]
base_url: Option<String>,
/// An access token for the API
#[arg(short, long)]
token: Option<String>,
/// Skips the check for saved API access data
#[arg(short, long)]
no_saved_access: bool,
}
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
let base_url = args.base_url.unwrap();
let api = match if let Some(token) = args.token {
match Api::from_token(&base_url, token).await? {
Ok(a) => Some(a),
Err(_) => None,
}
} else if !args.no_saved_access {
Api::from_file().await?
} else {
None
} {
Some(a) => a,
None => {
let mut login = ui::login::UI::new(ui::prepare()?, base_url)?;
login.run().await?
}
};
let mut ui = ui::master::UI::new(api, ui::prepare()?)?;
ui.run().await?;
Ok(())
}