frequency_cli/
runtime_version_cmd.rs1use clap::Parser;
2use sc_cli::{CliConfiguration, Error, RuntimeVersion, SharedParams};
3use serde_json::{json, to_writer};
4use std::{fmt::Debug, fs, io, path::PathBuf};
5
6#[derive(Debug, Clone, Parser)]
8pub struct ExportRuntimeVersionCmd {
9 #[clap(value_parser)]
11 pub output: Option<PathBuf>,
12
13 #[allow(missing_docs)]
14 #[clap(flatten)]
15 pub shared_params: SharedParams,
16}
17
18impl ExportRuntimeVersionCmd {
19 pub async fn run(&self, runtime_version: &RuntimeVersion) -> Result<(), Error> {
21 let result = json!(runtime_version);
22 let file: Box<dyn io::Write> = match &self.output {
23 Some(filename) => Box::new(fs::File::create(filename)?),
24 None => Box::new(io::stdout()),
25 };
26 to_writer(file, &result).map_err(|_| Error::from("export-runtime-version: failed encoding"))
27 }
28}
29
30impl CliConfiguration for ExportRuntimeVersionCmd {
31 fn shared_params(&self) -> &SharedParams {
32 &self.shared_params
33 }
34}