git.delta.rocks / jrsonnet / refs/commits / bb05d50f624d

difftreelog

fix dont use ArgGroup

Лач2020-07-19parent: #b0a4791.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth
before · crates/jrsonnet-cli/src/manifest.rs
1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{EvaluationState, ManifestFormat, Result};4use std::str::FromStr;56pub enum ManifestFormatName {7	/// Expect string as output, and write them directly8	None,9	Json,10	Yaml,11}1213impl FromStr for ManifestFormatName {14	type Err = &'static str;15	fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {16		Ok(match s {17			"none" => ManifestFormatName::None,18			"json" => ManifestFormatName::Json,19			"yaml" => ManifestFormatName::Yaml,20			_ => return Err("no such format"),21		})22	}23}2425#[derive(Clap)]26// #[clap(group = clap::ArgGroup::new("output_format"), help_heading = "MANIFESTIFICATION OUTPUT")]27pub struct ManifestOpts {28	/// Output format, wraps resulting value to corresponding std.manifest call.29	/// If none - then jsonnet file is expected to return plain string value, otherwise30	/// output will be serialized to specified format31	#[clap(long, short = 'f', default_value = "json", possible_values = &["none", "json", "yaml"], group = "output_format")]32	format: ManifestFormatName,33	/// Expect string as output, and write them directly.34	/// Shortcut for --format=none, and can't be set with format together35	#[clap(long, short = 'S', group = "output_format")]36	string: bool,37	/// Numbed of spaces to pad output manifest with.38	/// 0 for hard tabs, -1 for single line output39	#[clap(long, default_value = "4")]40	line_padding: usize,41}42impl ConfigureState for ManifestOpts {43	fn configure(&self, state: &EvaluationState) -> Result<()> {44		if self.string {45			state.set_manifest_format(ManifestFormat::None);46		} else {47			match self.format {48				ManifestFormatName::None => state.set_manifest_format(ManifestFormat::None),49				ManifestFormatName::Json => {50					state.set_manifest_format(ManifestFormat::Json(self.line_padding))51				}52				ManifestFormatName::Yaml => {53					state.set_manifest_format(ManifestFormat::Yaml(self.line_padding))54				}55			}56		}57		Ok(())58	}59}
after · crates/jrsonnet-cli/src/manifest.rs
1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{EvaluationState, ManifestFormat, Result};4use std::str::FromStr;56pub enum ManifestFormatName {7	/// Expect string as output, and write them directly8	None,9	Json,10	Yaml,11}1213impl FromStr for ManifestFormatName {14	type Err = &'static str;15	fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {16		Ok(match s {17			"none" => ManifestFormatName::None,18			"json" => ManifestFormatName::Json,19			"yaml" => ManifestFormatName::Yaml,20			_ => return Err("no such format"),21		})22	}23}2425#[derive(Clap)]26// TODO: Restore arg group after issue fixed in clap27// #[clap(group = clap::ArgGroup::new("output_format"), help_heading = "MANIFESTIFICATION OUTPUT")]28pub struct ManifestOpts {29	/// Output format, wraps resulting value to corresponding std.manifest call.30	/// If none - then jsonnet file is expected to return plain string value, otherwise31	/// output will be serialized to specified format32	#[clap(long, short = 'f', default_value = "json", possible_values = &["none", "json", "yaml"]/*, group = "output_format"*/)]33	format: ManifestFormatName,34	/// Expect string as output, and write them directly.35	/// Shortcut for --format=none, and can't be set with format together36	#[clap(long, short = 'S'/*, group = "output_format"*/)]37	string: bool,38	/// Numbed of spaces to pad output manifest with.39	/// 0 for hard tabs, -1 for single line output40	#[clap(long, default_value = "4")]41	line_padding: usize,42}43impl ConfigureState for ManifestOpts {44	fn configure(&self, state: &EvaluationState) -> Result<()> {45		if self.string {46			state.set_manifest_format(ManifestFormat::None);47		} else {48			match self.format {49				ManifestFormatName::None => state.set_manifest_format(ManifestFormat::None),50				ManifestFormatName::Json => {51					state.set_manifest_format(ManifestFormat::Json(self.line_padding))52				}53				ManifestFormatName::Yaml => {54					state.set_manifest_format(ManifestFormat::Yaml(self.line_padding))55				}56			}57		}58		Ok(())59	}60}