Refactor logic into their own source files
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(clap::ValueEnum, Clone, Default, Debug)]
|
||||
pub enum LoadMethod {
|
||||
Mmap,
|
||||
#[default]
|
||||
Datastore,
|
||||
Directly,
|
||||
}
|
||||
impl Display for LoadMethod {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let result = match self {
|
||||
LoadMethod::Mmap => "mmap",
|
||||
LoadMethod::Datastore => "datastore",
|
||||
LoadMethod::Directly => "directly",
|
||||
};
|
||||
write!(f, "{result}")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(clap::ValueEnum, Clone, Default, Debug)]
|
||||
pub enum RoutingAlgorithm {
|
||||
#[default]
|
||||
Ch,
|
||||
Mld,
|
||||
}
|
||||
|
||||
impl Display for RoutingAlgorithm {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let result = match self {
|
||||
RoutingAlgorithm::Ch => "ch",
|
||||
RoutingAlgorithm::Mld => "mld",
|
||||
};
|
||||
write!(f, "{result}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: move to external file
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub struct Args {
|
||||
// underlying memory storage
|
||||
#[arg(short, default_value_t = LoadMethod::Datastore)]
|
||||
memory: LoadMethod,
|
||||
|
||||
// Number of times to greet
|
||||
#[arg(short, default_value_t = RoutingAlgorithm::Ch)]
|
||||
p: RoutingAlgorithm,
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
pub mod cli_arguments;
|
||||
pub mod lexicographic_file_walker;
|
||||
pub mod nearest_response;
|
||||
pub mod osm;
|
||||
pub mod osm_db;
|
||||
pub mod osrm_world;
|
||||
pub mod scenario_id;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
pub fn scenario_id(scenario: &cucumber::gherkin::Scenario) -> String {
|
||||
// ports the following logic:
|
||||
// let name = scenario.getName().toLowerCase().replace(/[/\-'=,():*#]/g, '')
|
||||
// .replace(/\s/g, '_').replace(/__/g, '_').replace(/\.\./g, '.')
|
||||
// .substring(0, 64);
|
||||
let mut s = scenario
|
||||
.name
|
||||
.to_ascii_lowercase()
|
||||
.replace(
|
||||
&['/', '\\', '-', '\'', '=', ',', '(', ')', ':', '*', '#'][..],
|
||||
"",
|
||||
)
|
||||
.chars()
|
||||
.map(|x| match x {
|
||||
' ' => '_',
|
||||
_ => x,
|
||||
})
|
||||
.collect::<String>()
|
||||
.replace('\\', "_")
|
||||
.replace("__", "_")
|
||||
.replace("..", ".");
|
||||
s.truncate(64);
|
||||
format!("{}_{}", scenario.position.line, s)
|
||||
}
|
||||
Reference in New Issue
Block a user