mirror of
https://github.com/Chaoscaot/schemsearch.git
synced 2025-11-04 21:54:00 +01:00
Abstractions
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use schemsearch_lib::SearchBehavior;
|
||||
use schemsearch_lib::{Match, SearchBehavior};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(tag = "event")]
|
||||
@ -12,10 +12,8 @@ pub enum JsonEvent {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct FoundEvent {
|
||||
pub name: String,
|
||||
pub x: u16,
|
||||
pub y: u16,
|
||||
pub z: u16,
|
||||
pub percent: f32,
|
||||
#[serde(flatten, rename = "match")]
|
||||
pub match_: Match,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
||||
@ -25,7 +25,7 @@ use clap::{command, Arg, ArgAction, ValueHint};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use clap::error::ErrorKind;
|
||||
use schemsearch_lib::{search, SearchBehavior};
|
||||
use schemsearch_lib::{Match, search, SearchBehavior};
|
||||
use crate::types::{PathSchematicSupplier, SchematicSupplierType};
|
||||
#[cfg(feature = "sql")]
|
||||
use futures::executor::block_on;
|
||||
@ -37,7 +37,7 @@ use schemsearch_sql::filter::SchematicFilter;
|
||||
use schemsearch_sql::load_all_schematics;
|
||||
#[cfg(feature = "sql")]
|
||||
use crate::types::SqlSchematicSupplier;
|
||||
use indicatif::{ParallelProgressIterator, ProgressStyle};
|
||||
use indicatif::*;
|
||||
use schemsearch_files::Schematic;
|
||||
use crate::sinks::{OutputFormat, OutputSink};
|
||||
|
||||
@ -253,7 +253,7 @@ fn main() {
|
||||
Some(x) => x,
|
||||
None => return SearchResult {
|
||||
name: schem.get_name(),
|
||||
matches: vec![]
|
||||
matches: Vec::default()
|
||||
}
|
||||
};
|
||||
SearchResult {
|
||||
@ -274,7 +274,7 @@ fn main() {
|
||||
println!("Error while loading schematic ({}): {}", schem.get_name(), e.to_string());
|
||||
SearchResult {
|
||||
name: schem.get_name(),
|
||||
matches: vec![]
|
||||
matches: Vec::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -312,6 +312,6 @@ fn load_schem(schem_path: &PathBuf) -> Option<Schematic> {
|
||||
#[derive(Debug, Clone)]
|
||||
struct SearchResult {
|
||||
name: String,
|
||||
matches: Vec<(u16, u16, u16, f32)>,
|
||||
matches: Vec<Match>,
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ use std::fs::File;
|
||||
use std::io::BufWriter;
|
||||
use std::str::FromStr;
|
||||
use std::io::Write;
|
||||
use schemsearch_lib::SearchBehavior;
|
||||
use schemsearch_lib::{Match, SearchBehavior};
|
||||
use crate::json_output::{EndEvent, FoundEvent, InitEvent, JsonEvent};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -52,16 +52,13 @@ impl OutputSink {
|
||||
}
|
||||
|
||||
impl OutputFormat {
|
||||
pub fn found_match(&self, name: &String, pos: (u16, u16, u16, f32)) -> String {
|
||||
pub fn found_match(&self, name: &String, pos: Match) -> String {
|
||||
match self {
|
||||
OutputFormat::Text => format!("Found match in '{}' at x: {}, y: {}, z: {}, % = {}\n", name, pos.0, pos.1, pos.2, pos.3),
|
||||
OutputFormat::CSV => format!("{},{},{},{},{}\n", name, pos.0, pos.1, pos.2, pos.3),
|
||||
OutputFormat::Text => format!("Found match in '{}' at x: {}, y: {}, z: {}, % = {}\n", name, pos.x, pos.y, pos.z, pos.percent),
|
||||
OutputFormat::CSV => format!("{},{},{},{},{}\n", name, pos.x, pos.y, pos.z, pos.percent),
|
||||
OutputFormat::JSON => format!("{}\n", serde_json::to_string(&JsonEvent::Found(FoundEvent {
|
||||
name: name.clone(),
|
||||
x: pos.0,
|
||||
y: pos.1,
|
||||
z: pos.2,
|
||||
percent: pos.3,
|
||||
match_: pos,
|
||||
})).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
use std::path::PathBuf;
|
||||
#[cfg(feature = "sql")]
|
||||
use futures::executor::block_on;
|
||||
#[allow(unused_imports)]
|
||||
use schemsearch_files::Schematic;
|
||||
#[cfg(feature = "sql")]
|
||||
use schemsearch_sql::{load_schemdata, SchematicNode};
|
||||
|
||||
Reference in New Issue
Block a user