This commit is contained in:
Biedermann Steve 2024-05-10 11:39:01 +02:00
parent ed2b803ce5
commit e16b92f526
1 changed files with 19 additions and 9 deletions

View File

@ -149,19 +149,29 @@ fn add_topics(output: &mut Vec<String>, topics: &IndexMap<String, Topic>, 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<Project> {
.or_else(|_| toml::from_str(value))?)
}
fn to_markdown(requirements: PathBuf) -> anyhow::Result<String> {
fn to_markdown(requirements: PathBuf, add_toc: bool) -> anyhow::Result<String> {
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<String> {
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 {