From 29fd54dcfa6aa3d0d4cf12f065ab3fd82c61925c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 5 Dec 2019 12:23:10 +0100 Subject: [PATCH] Allow users to send csv files from stdin in examples --- meilisearch-core/examples/from_file.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/meilisearch-core/examples/from_file.rs b/meilisearch-core/examples/from_file.rs index 854ab3f5d..dff8d1b2a 100644 --- a/meilisearch-core/examples/from_file.rs +++ b/meilisearch-core/examples/from_file.rs @@ -1,7 +1,7 @@ use std::collections::btree_map::{BTreeMap, Entry}; use std::collections::HashSet; use std::error::Error; -use std::io::Write; +use std::io::{Read, Write}; use std::iter::FromIterator; use std::path::{Path, PathBuf}; use std::time::{Duration, Instant}; @@ -24,7 +24,7 @@ struct IndexCommand { #[structopt(long, default_value = "default")] index_uid: String, - /// The csv file to index. + /// The csv file path to index, you can also use `-` to specify the standard input. #[structopt(parse(from_os_str))] csv_data_path: PathBuf, @@ -135,7 +135,13 @@ fn index_command(command: IndexCommand, database: Database) -> Result<(), Box) + } else { + let file = std::fs::File::open(command.csv_data_path)?; + csv::Reader::from_reader(Box::new(file) as Box) + }; + let mut raw_record = csv::StringRecord::new(); let headers = rdr.headers()?.clone();