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)]262728pub struct ManifestOpts {29 30 31 32 #[clap(long, short = 'f', default_value = "json", possible_values = &["none", "json", "yaml"])]33 format: ManifestFormatName,34 35 36 #[clap(long, short = 'S')]37 string: bool,38 39 40 #[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}