frequency_cli/
runtime_version_cmd.rs

1use 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/// The `export-runtime-version` command used to export the runtime version.
7#[derive(Debug, Clone, Parser)]
8pub struct ExportRuntimeVersionCmd {
9	/// Output file name or stdout if unspecified.
10	#[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	/// Run the export-runtime-version command.
20	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}