diff --git a/src/main.rs b/src/main.rs index 20e0e8c..153ce2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,19 +149,29 @@ fn add_topics(output: &mut Vec, topics: &IndexMap, level: #[derive(Parser)] enum Command { + /// Outputs the JSON schema for the input data Schema, + /// Outputs demo data in YAML format Demo, #[clap(alias = "md")] + /// Transform requirements into Markdown Markdown { + /// The path to the requirements file requirements: PathBuf, }, + /// Transform requirements into HTML Html { + /// The path to the requirements file requirements: PathBuf, }, + /// Check test output against requirements Check { #[arg(short, long, default_value = "REQ-.*")] + /// Regex to select which requirements should be checked allowed_requirements: String, + /// The path to the requirements file requirements: PathBuf, + /// The path to the test output file test_results: PathBuf, }, } @@ -179,14 +189,14 @@ fn parse(value: &str) -> anyhow::Result { .or_else(|_| toml::from_str(value))?) } -fn to_markdown(requirements: PathBuf) -> anyhow::Result { +fn to_markdown(requirements: PathBuf, add_toc: bool) -> anyhow::Result { let project: Project = parse(&std::fs::read_to_string(requirements)?)?; - let mut output = vec![ - format!("# Requirements for {}", project.name.trim()), - nl(), - s!("[[_TOC_]]"), - nl(), + let mut output = vec![format!("# Requirements for {}", project.name.trim()), nl()]; + if add_toc { + output.extend([s!("[[_TOC_]]"), nl()]); + } + output.extend([ WORD_DESCRIPTION.trim().to_string(), nl(), format!("**VERSION: {}**", project.version), @@ -194,7 +204,7 @@ fn to_markdown(requirements: PathBuf) -> anyhow::Result { s!("## Description"), project.description.trim().to_string(), nl(), - ]; + ]); if !project.topics.is_empty() { output.push(s!("## Requirements")); @@ -266,7 +276,7 @@ fn main() -> anyhow::Result<()> { println!("{}", serde_yaml::to_string(&demo_project())?); } Command::Html { requirements } => { - let output = to_markdown(requirements)?; + let output = to_markdown(requirements, false)?; println!( "{}", markdown::to_html_with_options(&output, &markdown::Options::gfm()) @@ -278,7 +288,7 @@ fn main() -> anyhow::Result<()> { println!("{}", serde_json::to_string_pretty(&schema).unwrap()); } Command::Markdown { requirements } => { - let output = to_markdown(requirements)?; + let output = to_markdown(requirements, true)?; println!("{output}"); } Command::Check {