difftreelog
docs Fix docs of manifest.rs
in: master
1 file changed
crates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{error::Result, EvaluationState, ManifestFormat};4use std::str::FromStr;56pub enum ManifestFormatName {7 /// Expect string as output, and write them directly8 String,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 "string" => ManifestFormatName::String,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 string - 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 = &["string", "json", "yaml"]/*, group = "output_format"*/)]33 format: ManifestFormatName,34 /// Expect string as output, and write them directly.35 /// Shortcut for --format=string, and can't be set with format together36 #[clap(long, short = 'S'/*, group = "output_format"*/)]37 string: bool,38 /// Write output as YAML stream, can be used with --format json/yaml39 #[clap(long, short = 'y')]40 yaml_stream: bool,41 /// Numbed of spaces to pad output manifest with.42 /// 0 for hard tabs, -1 for single line output43 #[clap(long, default_value = "3")]44 line_padding: usize,45}46impl ConfigureState for ManifestOpts {47 fn configure(&self, state: &EvaluationState) -> Result<()> {48 if self.string {49 state.set_manifest_format(ManifestFormat::String);50 } else {51 match self.format {52 ManifestFormatName::String => state.set_manifest_format(ManifestFormat::String),53 ManifestFormatName::Json => {54 state.set_manifest_format(ManifestFormat::Json(self.line_padding))55 }56 ManifestFormatName::Yaml => {57 state.set_manifest_format(ManifestFormat::Yaml(self.line_padding))58 }59 }60 }61 if self.yaml_stream {62 state.set_manifest_format(ManifestFormat::YamlStream(Box::new(63 state.manifest_format(),64 )))65 }66 Ok(())67 }68}1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{error::Result, EvaluationState, ManifestFormat};4use std::str::FromStr;56pub enum ManifestFormatName {7 /// Expect string as output, and write them directly8 String,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 "string" => ManifestFormatName::String,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 set to `string` then plain string value is expected to be returned,31 /// otherwise output will be serialized to the specified format.32 #[clap(long, short = 'f', default_value = "json", possible_values = &["string", "json", "yaml"]/*, group = "output_format"*/)]33 format: ManifestFormatName,34 /// Expect plain string as output.35 /// Shortcut for `--format=string` thus this option is mutually exclusive with `format` option.36 #[clap(long, short = 'S'/*, group = "output_format"*/)]37 string: bool,38 /// Write output as YAML stream, can be used with --format json/yaml39 #[clap(long, short = 'y')]40 yaml_stream: bool,41 /// Number of spaces to pad output manifest with.42 /// `0` for hard tabs, `-1` for single line output/43 #[clap(long, default_value = "3")]44 line_padding: usize,45}46impl ConfigureState for ManifestOpts {47 fn configure(&self, state: &EvaluationState) -> Result<()> {48 if self.string {49 state.set_manifest_format(ManifestFormat::String);50 } else {51 match self.format {52 ManifestFormatName::String => state.set_manifest_format(ManifestFormat::String),53 ManifestFormatName::Json => {54 state.set_manifest_format(ManifestFormat::Json(self.line_padding))55 }56 ManifestFormatName::Yaml => {57 state.set_manifest_format(ManifestFormat::Yaml(self.line_padding))58 }59 }60 }61 if self.yaml_stream {62 state.set_manifest_format(ManifestFormat::YamlStream(Box::new(63 state.manifest_format(),64 )))65 }66 Ok(())67 }68}