-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hugr-cli)!: move mermaid to own sub-command (#1390)
drive-by replace `clap_stdin` with `clio` as that's that `clap` recommends, and it comes with stdout too. BREAKING CHANGE: Cli validate command no longer has a mermaid option, use `mermaid` sub-command instead.
- Loading branch information
Showing
8 changed files
with
248 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! Render mermaid diagrams. | ||
use std::io::Write; | ||
|
||
use clap::Parser; | ||
use clio::Output; | ||
use hugr_core::HugrView; | ||
|
||
/// Dump the standard extensions. | ||
#[derive(Parser, Debug)] | ||
#[clap(version = "1.0", long_about = None)] | ||
#[clap(about = "Render mermaid diagrams..")] | ||
#[group(id = "hugr")] | ||
#[non_exhaustive] | ||
pub struct MermaidArgs { | ||
/// Common arguments | ||
#[command(flatten)] | ||
pub hugr_args: crate::HugrArgs, | ||
/// Validate package. | ||
#[arg( | ||
long, | ||
help = "Validate before rendering, includes extension inference." | ||
)] | ||
pub validate: bool, | ||
/// Output file '-' for stdout | ||
#[clap(long, short, value_parser, default_value = "-")] | ||
output: Output, | ||
} | ||
|
||
impl MermaidArgs { | ||
/// Write the mermaid diagram to the output. | ||
pub fn run_print(&mut self) -> Result<(), crate::CliError> { | ||
let hugrs = if self.validate { | ||
self.hugr_args.validate()? | ||
} else { | ||
self.hugr_args.get_package()?.modules | ||
}; | ||
|
||
for hugr in hugrs { | ||
write!(self.output, "{}", hugr.mermaid_string())?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.