aboutsummaryrefslogtreecommitdiffstats
path: root/rst/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rst/src/main.rs')
-rw-r--r--rst/src/main.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/rst/src/main.rs b/rst/src/main.rs
index 318bcb6..1418a5e 100644
--- a/rst/src/main.rs
+++ b/rst/src/main.rs
@@ -12,6 +12,8 @@ use rst_renderer::{
render_html,
};
+use std::io::{self, Read};
+
arg_enum! {
#[derive(Debug)]
#[allow(non_camel_case_types)]
@@ -26,7 +28,7 @@ struct Cli {
raw(possible_values = "&Format::variants()", case_insensitive = "true"),
)]
format: Format,
- file: String,
+ file: Option<String>,
#[structopt(flatten)]
verbosity: Verbosity,
}
@@ -34,9 +36,18 @@ struct Cli {
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 content = read_file(args.file)?.replace('\t', " ".repeat(8).as_ref());
+ let content = content.replace('\t', " ".repeat(8).as_ref());
let document = parse(&content)?;
let stdout = std::io::stdout();
match args.format {