Skip to main content

haste_health/commands/
doc.rs

1use haste_fhir_operation_error::OperationOutcomeError;
2
3use crate::Cli;
4
5/// Runs the `doc` command: renders this CLI's `--help` text for every command to Markdown.
6pub(crate) async fn run(output: &str) -> Result<(), OperationOutcomeError> {
7    let markdown: String = clap_markdown::help_markdown::<Cli>();
8
9    let top_string = "
10| Context | Invocation                     |
11| ------- | ------------------------------ |
12| Source  | `cargo run <command>`          |
13| Binary  | `./haste-health <command>`     |
14| Docker  | `docker run <image> <command>` |
15";
16
17    let markdown = format!("{top_string}\n\n{markdown}");
18
19    tokio::fs::write(output, markdown).await.map_err(|e| {
20        OperationOutcomeError::error(
21            haste_fhir_model::r4::generated::terminology::IssueType::exception(),
22            e.to_string(),
23        )
24    })?;
25
26    Ok(())
27}