diff options
Diffstat (limited to 'rst')
| -rw-r--r-- | rst/Cargo.toml | 19 | ||||
| -rw-r--r-- | rst/src/main.rs | 47 | 
2 files changed, 66 insertions, 0 deletions
| diff --git a/rst/Cargo.toml b/rst/Cargo.toml new file mode 100644 index 0000000..3d1d6f2 --- /dev/null +++ b/rst/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = 'rst' +version = '0.2.0' +authors = ['Philipp A. <flying-sheep@web.de>'] +edition = '2018' +description = 'a reStructuredText parser and renderer for the command line' +license = 'MIT OR Apache-2.0' + +documentation = 'https://flying-sheep.github.io/rust-rst' +homepage = 'https://github.com/flying-sheep/rust-rst' +repository = 'https://github.com/flying-sheep/rust-rst.git' + +[dependencies] +rst_renderer = { path = '../renderer' } +rst_parser = { path = '../parser' } + +quicli = '0.4.0' +structopt = '0.2.15' +clap = '2.32.0' diff --git a/rst/src/main.rs b/rst/src/main.rs new file mode 100644 index 0000000..3c0b8e5 --- /dev/null +++ b/rst/src/main.rs @@ -0,0 +1,47 @@ +use structopt::StructOpt; +use clap::arg_enum; +use quicli::{ +	fs::read_file, +	prelude::{CliResult,Verbosity}, +}; + +use rst_parser::parse; +use rst_renderer::{ +	render_json, +	render_xml, +	render_html, +}; + +arg_enum! { +	#[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, +} + +fn main() -> CliResult { +	let args = Cli::from_args(); +	args.verbosity.setup_env_logger("rst")?; +	 +	let content = read_file(args.file)?; +	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(()) +} | 
