configure param

This commit is contained in:
MeexReay 2025-02-10 22:21:33 +03:00
parent ea396bab51
commit 276248a47f
3 changed files with 60 additions and 43 deletions

View File

@ -57,6 +57,7 @@ max_messages: 100 # chat messages limit
-c, --disable-commands Disable slash commands
-i, --disable-ip-hiding Disable ip hiding
-v, --enable-users-ip-viewing Enable users IP viewing
-C, --configure Configure client
-h, --help Print help
-V, --version Print version
```

View File

@ -29,8 +29,7 @@ fn default_update_time() -> usize { 50 }
fn default_host() -> String { "meex.lol:11234".to_string() }
fn default_message_format() -> String { MESSAGE_FORMAT.to_string() }
pub fn load_config(path: PathBuf) -> Config {
if !fs::exists(&path).unwrap_or_default() {
pub fn configure(path: PathBuf) -> Config {
let host = get_input("Host (default: meex.lol:11234) > ").unwrap_or("meex.lol:11234".to_string());
let name = get_input("Name (default: ask every time) > ");
let update_time = get_input("Update interval (default: 50) > ").map(|o| o.parse().ok()).flatten().unwrap_or(50);
@ -47,10 +46,18 @@ pub fn load_config(path: PathBuf) -> Config {
enable_ip_viewing,
disable_ip_hiding
};
let config_text = serde_yml::to_string(&config).expect("Config save error");
fs::create_dir_all(&path.parent().expect("Config save error")).expect("Config save error");
fs::write(&path, config_text).expect("Config save error");
println!("Config saved! You can edit it in the path got with `bRAC --config-path`");
config
}
pub fn load_config(path: PathBuf) -> Config {
if !fs::exists(&path).unwrap_or_default() {
let config = configure(path.clone());
thread::sleep(Duration::from_secs(4));
config
} else {

View File

@ -3,7 +3,7 @@ use std::{
};
use colored::Color;
use config::{get_config_path, load_config};
use config::{configure, get_config_path, load_config};
use rac::{read_messages, run_recv_loop, send_message};
use rand::random;
use regex::Regex;
@ -103,7 +103,7 @@ struct Args {
host: Option<String>,
/// Use specified name
#[arg(short, long)]
#[arg(short='n', long)]
name: Option<String>,
/// Use specified message format
@ -111,11 +111,11 @@ struct Args {
message_format: Option<String>,
/// Print unformatted messages from chat and exit
#[arg(short, long)]
#[arg(short='r', long)]
read_messages: bool,
/// Send unformatted message to chat and exit
#[arg(short, long, value_name="MESSAGE")]
#[arg(short='s', long, value_name="MESSAGE")]
send_message: Option<String>,
/// Disable message formatting and sanitizing
@ -133,6 +133,10 @@ struct Args {
/// Enable users IP viewing
#[arg(short='v', long)]
enable_users_ip_viewing: bool,
/// Configure client
#[arg(short='C', long)]
configure: bool,
}
@ -154,7 +158,6 @@ struct Context {
fn main() {
let args = Args::parse();
let context = {
let config_path = get_config_path();
if args.config_path {
@ -162,6 +165,12 @@ fn main() {
return;
}
if args.configure {
configure(config_path);
return;
}
let context = {
let config = load_config(config_path);
Context {