rain_metadata/cli/solc/
artifact.rs1use clap::Parser;
2use std::path::PathBuf;
3use crate::solc::ArtifactComponent;
4use crate::cli::output::SupportedOutputEncoding;
5
6#[derive(Parser)]
7pub struct Artifact {
8 #[arg(value_parser = clap::value_parser!(ArtifactComponent), short, long)]
10 component: ArtifactComponent,
11 #[arg(short, long)]
13 input_path: PathBuf,
14 #[arg(short, long)]
17 output_path: Option<PathBuf>,
18 #[arg(short, long)]
20 pretty_print: bool,
21 #[arg(short = 'E', long, default_value = "binary")]
22 output_encoding: SupportedOutputEncoding,
23}
24
25pub fn artifact(artifact: Artifact) -> anyhow::Result<()> {
26 let extracted_component = crate::solc::extract_artifact_component_json(
27 artifact.component,
28 &std::fs::read(artifact.input_path)?,
29 )?;
30
31 let component_string = if artifact.pretty_print {
32 serde_json::to_string_pretty(&extracted_component)?
33 } else {
34 serde_json::to_string(&extracted_component)?
35 };
36
37 crate::cli::output::output(
38 &artifact.output_path,
39 artifact.output_encoding,
40 component_string.as_bytes(),
41 )
42}