1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{EvaluationState, ManifestFormat, Result};4use std::str::FromStr;56pub enum ManifestFormatName {7 8 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)]2627pub struct ManifestOpts {28 29 30 31 #[clap(long, short = 'f', default_value = "json", possible_values = &["none", "json", "yaml"], group = "output_format")]32 format: ManifestFormatName,33 34 35 #[clap(long, short = 'S', group = "output_format")]36 string: bool,37 38 39 #[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}