add some fancy args

This commit is contained in:
galister
2024-02-27 22:01:31 +01:00
parent 7b9f5afd9d
commit da45c828fc
4 changed files with 150 additions and 18 deletions

109
Cargo.lock generated
View File

@@ -61,6 +61,54 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "anstream"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
[[package]]
name = "anstyle-parse"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.80" version = "1.0.80"
@@ -658,6 +706,46 @@ dependencies = [
"libloading 0.8.1", "libloading 0.8.1",
] ]
[[package]]
name = "clap"
version = "4.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.51",
]
[[package]]
name = "clap_lex"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
[[package]] [[package]]
name = "cmake" name = "cmake"
version = "0.1.50" version = "0.1.50"
@@ -677,6 +765,12 @@ dependencies = [
"unicode-width", "unicode-width",
] ]
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]] [[package]]
name = "combine" name = "combine"
version = "4.6.6" version = "4.6.6"
@@ -2784,6 +2878,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strsim"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
[[package]] [[package]]
name = "strum" name = "strum"
version = "0.25.0" version = "0.25.0"
@@ -3070,6 +3170,12 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]] [[package]]
name = "vec_map" name = "vec_map"
version = "0.8.2" version = "0.8.2"
@@ -3616,12 +3722,13 @@ dependencies = [
[[package]] [[package]]
name = "wlx-overlay-s" name = "wlx-overlay-s"
version = "0.2.1" version = "0.2.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"ash", "ash",
"chrono", "chrono",
"chrono-tz", "chrono-tz",
"clap",
"cstr", "cstr",
"ctrlc", "ctrlc",
"dbus", "dbus",

View File

@@ -14,6 +14,7 @@ anyhow = "1.0.79"
ash = "^0.37.2" ash = "^0.37.2"
chrono = "0.4.29" chrono = "0.4.29"
chrono-tz = "0.8.5" chrono-tz = "0.8.5"
clap = { version = "4.5.1", features = ["derive"] }
cstr = "0.2.11" cstr = "0.2.11"
ctrlc = { version = "3.4.2", features = ["termination"] } ctrlc = { version = "3.4.2", features = ["termination"] }
dbus = { version = "0.9.7" } dbus = { version = "0.9.7" }

View File

@@ -9,23 +9,47 @@ mod overlays;
mod shaders; mod shaders;
mod state; mod state;
use std::{ use std::sync::{
io::{stdout, IsTerminal}, atomic::{AtomicBool, Ordering},
sync::{ Arc,
atomic::{AtomicBool, Ordering},
Arc,
},
}; };
use clap::Parser;
use flexi_logger::FileSpec; 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>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
if stdout().is_terminal() { let args = Args::parse();
flexi_logger::Logger::try_with_env_or_str("info")?.start()?; if let Some(log_to) = args.log_to {
} else {
flexi_logger::Logger::try_with_env_or_str("info")? 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()?; .start()?;
println!("Logging to: {}", &log_to);
} else {
flexi_logger::Logger::try_with_env_or_str("info")?.start()?;
} }
log::info!( log::info!(
@@ -35,7 +59,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
); );
#[cfg(feature = "openvr")] #[cfg(feature = "openvr")]
if std::env::args().any(|arg| arg == "--uninstall") { if args.uninstall {
crate::backend::openvr::openvr_uninstall(); crate::backend::openvr::openvr_uninstall();
return Ok(()); 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(()) Ok(())
} }
fn auto_run(running: Arc<AtomicBool>) { fn auto_run(running: Arc<AtomicBool>, openvr: bool, openxr: bool) {
use backend::common::BackendError; use backend::common::BackendError;
#[cfg(feature = "openxr")] #[cfg(feature = "openxr")]
{ if !openvr {
use crate::backend::openxr::openxr_run; use crate::backend::openxr::openxr_run;
match openxr_run(running.clone()) { match openxr_run(running.clone()) {
Ok(()) => return, Ok(()) => return,
@@ -70,7 +94,7 @@ fn auto_run(running: Arc<AtomicBool>) {
} }
#[cfg(feature = "openvr")] #[cfg(feature = "openvr")]
{ if !openxr {
use crate::backend::openvr::openvr_run; use crate::backend::openvr::openvr_run;
match openvr_run(running.clone()) { match openvr_run(running.clone()) {
Ok(()) => return, 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");
} }

View File

@@ -44,7 +44,7 @@ use crate::{
overlay::{OverlayData, OverlayRenderer, OverlayState, SplitOverlayBackend}, overlay::{OverlayData, OverlayRenderer, OverlayState, SplitOverlayBackend},
}, },
config::def_pw_tokens, config::def_pw_tokens,
graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy, BLEND_ALPHA}, graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy},
hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT}, hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT},
state::{AppSession, AppState}, state::{AppSession, AppState},
}; };