mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-04 17:23:33 +01:00
core: add sign pattern command line argument handling
This commit is contained in:
parent
6da921cca3
commit
9fd5689ebb
4 changed files with 75 additions and 4 deletions
39
Cargo.lock
generated
39
Cargo.lock
generated
|
@ -29,6 +29,15 @@ dependencies = [
|
||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "allocator-api2"
|
name = "allocator-api2"
|
||||||
version = "0.2.16"
|
version = "0.2.16"
|
||||||
|
@ -554,6 +563,7 @@ dependencies = [
|
||||||
"num-integer",
|
"num-integer",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"rayon",
|
"rayon",
|
||||||
|
"regex",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -775,6 +785,35 @@ dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.23"
|
version = "0.1.23"
|
||||||
|
|
|
@ -52,6 +52,7 @@ minedmap-types = { version = "0.1.2", path = "crates/types" }
|
||||||
num-integer = "0.1.45"
|
num-integer = "0.1.45"
|
||||||
num_cpus = "1.16.0"
|
num_cpus = "1.16.0"
|
||||||
rayon = "1.7.0"
|
rayon = "1.7.0"
|
||||||
|
regex = "1.10.2"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
serde = { version = "1.0.152", features = ["rc", "derive"] }
|
serde = { version = "1.0.152", features = ["rc", "derive"] }
|
||||||
serde_json = "1.0.99"
|
serde_json = "1.0.99"
|
||||||
|
|
|
@ -6,7 +6,9 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use anyhow::{Context, Result};
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
|
use regex::RegexSet;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -147,11 +149,13 @@ pub struct Config {
|
||||||
pub viewer_info_path: PathBuf,
|
pub viewer_info_path: PathBuf,
|
||||||
/// Path of viewer entities file
|
/// Path of viewer entities file
|
||||||
pub viewer_entities_path: PathBuf,
|
pub viewer_entities_path: PathBuf,
|
||||||
|
/// Sign text filter patterns
|
||||||
|
pub sign_patterns: RegexSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
/// Crates a new [Config] from [command line arguments](super::Args)
|
/// Crates a new [Config] from [command line arguments](super::Args)
|
||||||
pub fn new(args: &super::Args) -> Self {
|
pub fn new(args: &super::Args) -> Result<Self> {
|
||||||
let num_threads = match args.jobs {
|
let num_threads = match args.jobs {
|
||||||
Some(0) => num_cpus::get(),
|
Some(0) => num_cpus::get(),
|
||||||
Some(threads) => threads,
|
Some(threads) => threads,
|
||||||
|
@ -168,7 +172,9 @@ impl Config {
|
||||||
.iter()
|
.iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Config {
|
let sign_patterns = Self::sign_patterns(args).context("Failed to parse sign patterns")?;
|
||||||
|
|
||||||
|
Ok(Config {
|
||||||
num_threads,
|
num_threads,
|
||||||
region_dir,
|
region_dir,
|
||||||
level_dat_path,
|
level_dat_path,
|
||||||
|
@ -178,7 +184,20 @@ impl Config {
|
||||||
entities_path_final,
|
entities_path_final,
|
||||||
viewer_info_path,
|
viewer_info_path,
|
||||||
viewer_entities_path,
|
viewer_entities_path,
|
||||||
}
|
sign_patterns,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses the sign prefixes and sign filters into a [RegexSet]
|
||||||
|
fn sign_patterns(args: &super::Args) -> Result<RegexSet> {
|
||||||
|
let prefix_patterns: Vec<_> = args
|
||||||
|
.sign_prefix
|
||||||
|
.iter()
|
||||||
|
.map(|prefix| format!("^{}", regex::escape(prefix)))
|
||||||
|
.collect();
|
||||||
|
Ok(RegexSet::new(
|
||||||
|
prefix_patterns.iter().chain(args.sign_filter.iter()),
|
||||||
|
)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs the path to an input region file
|
/// Constructs the path to an input region file
|
||||||
|
|
|
@ -47,6 +47,18 @@ pub struct Args {
|
||||||
/// Enable verbose messages
|
/// Enable verbose messages
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
|
/// Prefix for text of signs to show on the map
|
||||||
|
#[arg(long)]
|
||||||
|
pub sign_prefix: Vec<String>,
|
||||||
|
/// Regular expression for text of signs to show on the map
|
||||||
|
///
|
||||||
|
/// --sign-prefix and --sign-filter allow to filter for signs to display;
|
||||||
|
/// by default, none are visible. The options may be passed multiple times,
|
||||||
|
/// and a sign will be visible if it matches any pattern.
|
||||||
|
///
|
||||||
|
/// To make all signs visible, pass an empty string to either option.
|
||||||
|
#[arg(long)]
|
||||||
|
pub sign_filter: Vec<String>,
|
||||||
/// Minecraft save directory
|
/// Minecraft save directory
|
||||||
pub input_dir: PathBuf,
|
pub input_dir: PathBuf,
|
||||||
/// MinedMap data directory
|
/// MinedMap data directory
|
||||||
|
@ -64,7 +76,7 @@ fn setup_threads(num_threads: usize) -> Result<()> {
|
||||||
/// MinedMap CLI main function
|
/// MinedMap CLI main function
|
||||||
pub fn cli() -> Result<()> {
|
pub fn cli() -> Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let config = Config::new(&args);
|
let config = Config::new(&args)?;
|
||||||
|
|
||||||
tracing_subscriber::fmt()
|
tracing_subscriber::fmt()
|
||||||
.with_max_level(if args.verbose {
|
.with_max_level(if args.verbose {
|
||||||
|
|
Loading…
Add table
Reference in a new issue