mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 13:38:04 +03:00
configure param
This commit is contained in:
parent
ea396bab51
commit
276248a47f
25
readme.md
25
readme.md
@ -47,18 +47,19 @@ max_messages: 100 # chat messages limit
|
||||
## command args
|
||||
|
||||
```
|
||||
-p, --config-path Print config path
|
||||
-H, --host <HOST> Use specified host
|
||||
-n, --name <NAME> Use specified name
|
||||
-F, --message-format <MESSAGE_FORMAT> Use specified message format
|
||||
-r, --read-messages Print unformatted messages from chat and exit
|
||||
-s, --send-message <MESSAGE> Send unformatted message to chat and exit
|
||||
-f, --disable-formatting Disable message formatting and sanitizing
|
||||
-c, --disable-commands Disable slash commands
|
||||
-i, --disable-ip-hiding Disable ip hiding
|
||||
-v, --enable-users-ip-viewing Enable users IP viewing
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
-p, --config-path Print config path
|
||||
-H, --host <HOST> Use specified host
|
||||
-n, --name <NAME> Use specified name
|
||||
-F, --message-format <MESSAGE_FORMAT> Use specified message format
|
||||
-r, --read-messages Print unformatted messages from chat and exit
|
||||
-s, --send-message <MESSAGE> Send unformatted message to chat and exit
|
||||
-f, --disable-formatting Disable message formatting and sanitizing
|
||||
-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
|
||||
```
|
||||
|
||||
## commands
|
||||
|
@ -29,28 +29,35 @@ 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 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);
|
||||
let max_messages = get_input("Max messages (default: 100) > ").map(|o| o.parse().ok()).flatten().unwrap_or(100);
|
||||
let enable_ip_viewing = get_input("Enable users IP viewing? (Y/N, default: N) > ").map(|o| o.to_lowercase() != "n").unwrap_or(false);
|
||||
let disable_ip_hiding = get_input("Enable your IP viewing? (Y/N, default: N) > ").map(|o| o.to_lowercase() != "n").unwrap_or(false);
|
||||
|
||||
let config = Config {
|
||||
host,
|
||||
name,
|
||||
message_format: MESSAGE_FORMAT.to_string(),
|
||||
update_time,
|
||||
max_messages,
|
||||
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 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);
|
||||
let max_messages = get_input("Max messages (default: 100) > ").map(|o| o.parse().ok()).flatten().unwrap_or(100);
|
||||
let enable_ip_viewing = get_input("Enable users IP viewing? (Y/N, default: N) > ").map(|o| o.to_lowercase() != "n").unwrap_or(false);
|
||||
let disable_ip_hiding = get_input("Enable your IP viewing? (Y/N, default: N) > ").map(|o| o.to_lowercase() != "n").unwrap_or(false);
|
||||
|
||||
let config = Config {
|
||||
host,
|
||||
name,
|
||||
message_format: MESSAGE_FORMAT.to_string(),
|
||||
update_time,
|
||||
max_messages,
|
||||
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`");
|
||||
let config = configure(path.clone());
|
||||
thread::sleep(Duration::from_secs(4));
|
||||
config
|
||||
} else {
|
||||
|
31
src/main.rs
31
src/main.rs
@ -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,14 +158,19 @@ struct Context {
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
|
||||
let config_path = get_config_path();
|
||||
|
||||
if args.config_path {
|
||||
print!("{}", config_path.to_string_lossy());
|
||||
return;
|
||||
}
|
||||
|
||||
if args.configure {
|
||||
configure(config_path);
|
||||
return;
|
||||
}
|
||||
|
||||
let context = {
|
||||
let config_path = get_config_path();
|
||||
|
||||
if args.config_path {
|
||||
print!("{}", config_path.to_string_lossy());
|
||||
return;
|
||||
}
|
||||
|
||||
let config = load_config(config_path);
|
||||
|
||||
Context {
|
||||
|
Loading…
Reference in New Issue
Block a user