Skip to content

Commit

Permalink
Add command line parameters to specify output files
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristramg committed Jan 26, 2024
1 parent 34be0f5 commit 3491285
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ use clap::Parser;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
/// Input OpenStreetMap in the .pbf format
source_pbf: String,
/// Output path of the csv file that will contain the nodes
#[arg(short, long, default_value = "nodes.csv")]
nodes_file: String,
/// Output path of the csv file that will contain the edges
#[arg(short, long, default_value = "nodes.csv")]
edges_file: String,
}
fn main() {
let cli = Cli::parse();

match osm4routing::read(&cli.source_pbf) {
Ok((nodes, edges)) => osm4routing::writers::csv(nodes, edges),
Ok((nodes, edges)) => {
osm4routing::writers::csv(nodes, edges, &cli.nodes_file, &cli.edges_file)
}
Err(error) => println!("Error: {}", error),
}
}
6 changes: 3 additions & 3 deletions src/osm4routing/writers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::models::*;

pub fn csv(nodes: Vec<Node>, edges: Vec<Edge>) {
let edges_path = std::path::Path::new("edges.csv");
pub fn csv(nodes: Vec<Node>, edges: Vec<Edge>, nodes_file: &str, edges_file: &str) {
let edges_path = std::path::Path::new(edges_file);
let mut edges_csv = csv::Writer::from_path(edges_path).unwrap();
edges_csv
.serialize(vec![
Expand Down Expand Up @@ -38,7 +38,7 @@ pub fn csv(nodes: Vec<Node>, edges: Vec<Edge>) {
.expect("CSV: unable to write edge");
}

let nodes_path = std::path::Path::new("nodes.csv");
let nodes_path = std::path::Path::new(nodes_file);
let mut nodes_csv = csv::Writer::from_path(nodes_path).unwrap();
nodes_csv
.serialize(vec!["id", "lon", "lat"])
Expand Down

0 comments on commit 3491285

Please sign in to comment.