aboutsummaryrefslogtreecommitdiffstats
path: root/rst/src/main.rs
diff options
context:
space:
mode:
authorPhilipp A2023-12-28 15:29:19 +0100
committerGitHub2023-12-28 15:29:19 +0100
commit2a76f2dde6533c09f8e93b44d1f214a105d9c5c2 (patch)
tree84d87ba7e14e86dbba43f2f46f9723c823631ecd /rst/src/main.rs
parentc0441bff302e724bb8f98420459a2c672e2286c6 (diff)
downloadrust-rst-2a76f2dde6533c09f8e93b44d1f214a105d9c5c2.tar.bz2
Format (#38)
Diffstat (limited to 'rst/src/main.rs')
-rw-r--r--rst/src/main.rs58
1 files changed, 27 insertions, 31 deletions
diff --git a/rst/src/main.rs b/rst/src/main.rs
index cf16b16..0339ce1 100644
--- a/rst/src/main.rs
+++ b/rst/src/main.rs
@@ -1,48 +1,44 @@
-use structopt::StructOpt;
use clap::arg_enum;
use quicli::{
- fs::read_file,
- prelude::{CliResult,Verbosity},
+ fs::read_file,
+ prelude::{CliResult, Verbosity},
};
+use structopt::StructOpt;
use rst_parser::parse;
-use rst_renderer::{
- render_json,
- render_xml,
- render_html,
-};
+use rst_renderer::{render_html, render_json, render_xml};
arg_enum! {
- #[derive(Debug)]
- #[allow(non_camel_case_types)]
- enum Format { json, xml, html }
+ #[derive(Debug)]
+ #[allow(non_camel_case_types)]
+ enum Format { json, xml, html }
}
#[derive(Debug, StructOpt)]
#[structopt(raw(setting = "structopt::clap::AppSettings::ColoredHelp"))]
struct Cli {
- #[structopt(
- long = "format", short = "f", default_value = "html", // xml is pretty defunct…
- raw(possible_values = "&Format::variants()", case_insensitive = "true"),
- )]
- format: Format,
- file: String,
- #[structopt(flatten)]
- verbosity: Verbosity,
+ #[structopt(
+ long = "format", short = "f", default_value = "html", // xml is pretty defunct…
+ raw(possible_values = "&Format::variants()", case_insensitive = "true"),
+ )]
+ format: Format,
+ file: String,
+ #[structopt(flatten)]
+ verbosity: Verbosity,
}
fn main() -> CliResult {
- let args = Cli::from_args();
- args.verbosity.setup_env_logger("rst")?;
+ let args = Cli::from_args();
+ args.verbosity.setup_env_logger("rst")?;
- // TODO: somehow make it work without replacing tabs
- let content = read_file(args.file)?.replace('\t', " ".repeat(8).as_ref());
- let document = parse(&content)?;
- let stdout = std::io::stdout();
- match args.format {
- Format::json => render_json(&document, stdout)?,
- Format::xml => render_xml (&document, stdout)?,
- Format::html => render_html(&document, stdout, true)?,
- }
- Ok(())
+ // TODO: somehow make it work without replacing tabs
+ let content = read_file(args.file)?.replace('\t', " ".repeat(8).as_ref());
+ let document = parse(&content)?;
+ let stdout = std::io::stdout();
+ match args.format {
+ Format::json => render_json(&document, stdout)?,
+ Format::xml => render_xml(&document, stdout)?,
+ Format::html => render_html(&document, stdout, true)?,
+ }
+ Ok(())
}