Skip to content

Commit e182a98

Browse files
0xkubectlShayBox
authored andcommitted
feat: add cli flag to force reset the settings without deleting the sqlite db
1 parent 485de83 commit e182a98

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ extern crate tracing;
33

44
use std::{
55
collections::HashSet,
6-
env::Args,
76
ffi::OsStr,
87
fs::{File, create_dir_all},
98
io::{BufRead, BufReader, Error},
@@ -123,10 +122,9 @@ pub fn watch<P: AsRef<Path>>(
123122
/// Will return `Err` if `Command::spawn` errors
124123
/// # Panics
125124
/// Will panic if `Child::wait` panics
126-
pub fn launch_game(args: Args) -> Result<()> {
127-
let args = args.collect::<Vec<_>>();
125+
pub fn launch_game(args: &[String]) -> Result<()> {
128126
if args.len() > 1 {
129-
let mut child = Command::new(&args[1])
127+
let mut child = Command::new(args[1].clone())
130128
.args(args.iter().skip(2))
131129
.stderr(Stdio::null())
132130
.stdout(Stdio::null())

src/main.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ use crossterm::{execute, terminal::SetTitle};
1010
use derive_config::{ConfigError, DeriveTomlConfig};
1111
use notify::PollWatcher;
1212
use terminal_link::Link;
13-
use time::{macros::format_description, UtcOffset};
13+
use time::{UtcOffset, macros::format_description};
1414
use tokio::signal;
1515
use tracing::level_filters::LevelFilter;
16-
use tracing_subscriber::{fmt::time::OffsetTime, EnvFilter};
16+
use tracing_subscriber::{EnvFilter, fmt::time::OffsetTime};
1717
use vrc_log::{
18-
provider,
19-
provider::{avtrdb::AvtrDBActor, prelude::*, ProviderKind},
18+
CARGO_PKG_HOMEPAGE, provider,
19+
provider::{ProviderKind, avtrdb::AvtrDBActor, prelude::*},
2020
settings::Settings,
2121
vrchat::{VRCHAT_AMP_PATH, VRCHAT_LOW_PATH},
22-
CARGO_PKG_HOMEPAGE,
2322
};
2423

2524
/* Watchers will stop working if they get dropped. */
2625
static WATCHERS: OnceLock<Vec<PollWatcher>> = OnceLock::new();
2726

27+
#[allow(clippy::too_many_lines)]
2828
#[tokio::main]
2929
async fn main() -> Result<()> {
3030
#[cfg(feature = "title")]
@@ -50,18 +50,28 @@ async fn main() -> Result<()> {
5050
info!("{link}");
5151
}
5252

53-
let args = std::env::args();
54-
let settings = Settings::load().unwrap_or_else(|error| match error {
55-
ConfigError::Io(error) if error.kind() == ErrorKind::NotFound => {
56-
info!("Welcome to VRC-LOG! Please follow the setup wizard");
57-
Settings::try_wizard().expect("Failed to setup wizard")
58-
}
59-
error => {
60-
error!("There was an error loading the settings: {error}");
61-
error!("Most likely an update. Please follow the setup wizard");
62-
Settings::try_wizard().expect("Failed to setup wizard")
63-
}
64-
});
53+
let mut args = std::env::args().collect::<Vec<_>>();
54+
let force_wizard = args.iter().any(|arg| arg == "--wizard" || arg == "-w");
55+
if force_wizard {
56+
args.retain(|arg| arg != "--wizard" && arg != "-w");
57+
}
58+
59+
let settings = if force_wizard {
60+
info!("Setup wizard requested via flag");
61+
Settings::try_wizard().expect("Failed to setup wizard")
62+
} else {
63+
Settings::load().unwrap_or_else(|error| match error {
64+
ConfigError::Io(error) if error.kind() == ErrorKind::NotFound => {
65+
info!("Welcome to VRC-LOG! Please follow the setup wizard");
66+
Settings::try_wizard().expect("Failed to setup wizard")
67+
}
68+
error => {
69+
error!("There was an error loading the settings: {error}");
70+
error!("Most likely an update. Please follow the setup wizard");
71+
Settings::try_wizard().expect("Failed to setup wizard")
72+
}
73+
})
74+
};
6575

6676
let (tx, rx) = flume::unbounded();
6777
let _ = WATCHERS.set(vec![
@@ -78,7 +88,7 @@ async fn main() -> Result<()> {
7888
}
7989

8090
settings.save()?;
81-
vrc_log::launch_game(args)?;
91+
vrc_log::launch_game(&args)?;
8292

8393
// This is a little wonky, but effecively we are creating a controlled memory leak
8494
// which will be static for the rest of the programms runtime

0 commit comments

Comments
 (0)