add some fancy args
This commit is contained in:
56
src/main.rs
56
src/main.rs
@@ -9,23 +9,47 @@ mod overlays;
|
||||
mod shaders;
|
||||
mod state;
|
||||
|
||||
use std::{
|
||||
io::{stdout, IsTerminal},
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
},
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
};
|
||||
|
||||
use clap::Parser;
|
||||
use flexi_logger::FileSpec;
|
||||
|
||||
/// The lightweight desktop overlay for OpenVR and OpenXR
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
#[cfg(feature = "openvr")]
|
||||
/// Start overlay with OpenVR backend
|
||||
#[arg(long)]
|
||||
openvr: bool,
|
||||
|
||||
#[cfg(feature = "openxr")]
|
||||
/// Start overlay with OpenXR backend
|
||||
#[arg(long)]
|
||||
openxr: bool,
|
||||
|
||||
/// Uninstall OpenVR manifest and exit
|
||||
#[arg(long)]
|
||||
uninstall: bool,
|
||||
|
||||
/// Folder path to write logs to
|
||||
#[arg(short, long)]
|
||||
log_to: Option<String>,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if stdout().is_terminal() {
|
||||
flexi_logger::Logger::try_with_env_or_str("info")?.start()?;
|
||||
} else {
|
||||
let args = Args::parse();
|
||||
if let Some(log_to) = args.log_to {
|
||||
flexi_logger::Logger::try_with_env_or_str("info")?
|
||||
.log_to_file(FileSpec::default().directory("/tmp"))
|
||||
.log_to_file(FileSpec::default().directory(&log_to))
|
||||
.log_to_stdout()
|
||||
.start()?;
|
||||
println!("Logging to: {}", &log_to);
|
||||
} else {
|
||||
flexi_logger::Logger::try_with_env_or_str("info")?.start()?;
|
||||
}
|
||||
|
||||
log::info!(
|
||||
@@ -35,7 +59,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
);
|
||||
|
||||
#[cfg(feature = "openvr")]
|
||||
if std::env::args().any(|arg| arg == "--uninstall") {
|
||||
if args.uninstall {
|
||||
crate::backend::openvr::openvr_uninstall();
|
||||
return Ok(());
|
||||
}
|
||||
@@ -48,16 +72,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
});
|
||||
|
||||
auto_run(running);
|
||||
auto_run(running, args.openvr, args.openxr);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn auto_run(running: Arc<AtomicBool>) {
|
||||
fn auto_run(running: Arc<AtomicBool>, openvr: bool, openxr: bool) {
|
||||
use backend::common::BackendError;
|
||||
|
||||
#[cfg(feature = "openxr")]
|
||||
{
|
||||
if !openvr {
|
||||
use crate::backend::openxr::openxr_run;
|
||||
match openxr_run(running.clone()) {
|
||||
Ok(()) => return,
|
||||
@@ -70,7 +94,7 @@ fn auto_run(running: Arc<AtomicBool>) {
|
||||
}
|
||||
|
||||
#[cfg(feature = "openvr")]
|
||||
{
|
||||
if !openxr {
|
||||
use crate::backend::openvr::openvr_run;
|
||||
match openvr_run(running.clone()) {
|
||||
Ok(()) => return,
|
||||
@@ -82,5 +106,5 @@ fn auto_run(running: Arc<AtomicBool>) {
|
||||
};
|
||||
}
|
||||
|
||||
log::error!("No supported backends found");
|
||||
log::error!("No more backends to try");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user