pesde/src/main.rs

71 lines
2 KiB
Rust
Raw Normal View History

2024-07-12 23:09:37 +01:00
use crate::cli::get_token;
use clap::Parser;
use colored::Colorize;
use pesde::{AuthConfig, Project};
2024-07-17 18:38:01 +01:00
use std::fs::create_dir_all;
2024-03-04 20:18:49 +00:00
2024-07-12 23:09:37 +01:00
mod cli;
2024-07-22 21:00:09 +01:00
pub mod util;
2024-03-04 20:18:49 +00:00
2024-07-12 23:09:37 +01:00
#[derive(Parser, Debug)]
#[clap(version, about = "pesde is a feature-rich package manager for Luau")]
#[command(disable_version_flag = true)]
struct Cli {
/// Print version
#[arg(short = 'v', short_alias = 'V', long, action = clap::builder::ArgAction::Version)]
version: (),
2024-03-04 20:18:49 +00:00
2024-07-12 23:09:37 +01:00
#[command(subcommand)]
subcommand: cli::Subcommand,
2024-07-12 23:09:37 +01:00
}
fn main() {
pretty_env_logger::init();
2024-07-12 23:09:37 +01:00
let project_dirs =
directories::ProjectDirs::from("com", env!("CARGO_PKG_NAME"), env!("CARGO_BIN_NAME"))
.expect("couldn't get home directory");
let cwd = std::env::current_dir().expect("failed to get current working directory");
let cli = Cli::parse();
let data_dir = project_dirs.data_dir();
2024-07-17 18:38:01 +01:00
create_dir_all(data_dir).expect("failed to create data directory");
2024-07-12 23:09:37 +01:00
if let Err(err) = get_token(data_dir).and_then(|token| {
cli.subcommand.run(Project::new(
cwd,
data_dir,
AuthConfig::new().with_pesde_token(token),
))
}) {
2024-07-17 18:38:01 +01:00
eprintln!("{}: {err}\n", "error".red().bold());
2024-03-04 20:18:49 +00:00
2024-07-12 23:09:37 +01:00
let cause = err.chain().skip(1).collect::<Vec<_>>();
2024-03-04 20:18:49 +00:00
2024-07-12 23:09:37 +01:00
if !cause.is_empty() {
eprintln!("{}:", "caused by".red().bold());
for err in cause {
2024-07-17 18:38:01 +01:00
eprintln!(" - {err}");
2024-07-12 23:09:37 +01:00
}
}
2024-07-17 18:38:01 +01:00
let backtrace = err.backtrace();
match backtrace.status() {
std::backtrace::BacktraceStatus::Disabled => {
eprintln!(
"\n{}: set RUST_BACKTRACE=1 for a backtrace",
"help".yellow().bold()
);
}
std::backtrace::BacktraceStatus::Captured => {
eprintln!("\n{}:\n{backtrace}", "backtrace".yellow().bold());
}
_ => {
eprintln!("\n{}: not captured", "backtrace".yellow().bold());
}
}
2024-07-12 23:09:37 +01:00
std::process::exit(1);
2024-03-04 20:18:49 +00:00
}
}