diff options
Diffstat (limited to 'rst/src/main.rs')
| -rw-r--r-- | rst/src/main.rs | 15 | 
1 files changed, 13 insertions, 2 deletions
| diff --git a/rst/src/main.rs b/rst/src/main.rs index 8b616f9..6a7ed44 100644 --- a/rst/src/main.rs +++ b/rst/src/main.rs @@ -8,6 +8,8 @@ use structopt::StructOpt;  use rst_parser::parse;  use rst_renderer::{render_html, render_json, render_xml}; +use std::io::{self, Read}; +  arg_enum! {      #[derive(Debug)]      #[allow(non_camel_case_types)] @@ -22,7 +24,7 @@ struct Cli {          raw(possible_values = "&Format::variants()", case_insensitive = "true"),      )]      format: Format, -    file: String, +    file: Option<String>,      #[structopt(flatten)]      verbosity: Verbosity,  } @@ -31,6 +33,15 @@ fn main() -> CliResult {      let args = Cli::from_args();      args.verbosity.setup_env_logger("rst")?; +    let content = if let Some(file) = args.file { +        read_file(file)? +    } else { +        let mut stdin = String::new(); +        io::stdin().read_to_string(&mut stdin)?; + +        stdin +    }; +      // TODO: somehow make it work without replacing tabs      let mut content = read_file(args.file)?.replace('\t', " ".repeat(8).as_ref());      // Allows for less complex grammar @@ -41,7 +52,7 @@ fn main() -> CliResult {      let stdout = std::io::stdout();      match args.format {          Format::json => render_json(&document, stdout)?, -        Format::xml => render_xml(&document, stdout)?, +        Format::xml  => render_xml (&document, stdout)?,          Format::html => render_html(&document, stdout, true)?,      }      Ok(()) | 
