1use crate::ConfigureState;2use clap::Clap;3use jrsonnet_evaluator::{error::Result, EvaluationState, ManifestFormat};4use std::{path::PathBuf, str::FromStr};56pub enum ManifestFormatName {7 8 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#[clap(help_heading = "MANIFESTIFICATION OUTPUT")]27pub struct ManifestOpts {28 29 30 31 #[clap(long, short = 'f', default_value = "json", possible_values = &["string", "json", "yaml"])]32 format: ManifestFormatName,33 34 35 #[clap(long, short = 'S')]36 string: bool,37 38 #[clap(long, short = 'y')]39 yaml_stream: bool,40 41 42 #[clap(long)]43 line_padding: Option<usize>,44}45impl ConfigureState for ManifestOpts {46 fn configure(&self, state: &EvaluationState) -> Result<()> {47 if self.string {48 state.set_manifest_format(ManifestFormat::String);49 } else {50 match self.format {51 ManifestFormatName::String => state.set_manifest_format(ManifestFormat::String),52 ManifestFormatName::Json => {53 state.set_manifest_format(ManifestFormat::Json(self.line_padding.unwrap_or(3)))54 }55 ManifestFormatName::Yaml => {56 state.set_manifest_format(ManifestFormat::Yaml(self.line_padding.unwrap_or(2)))57 }58 }59 }60 if self.yaml_stream {61 state.set_manifest_format(ManifestFormat::YamlStream(Box::new(62 state.manifest_format(),63 )))64 }65 Ok(())66 }67}6869#[derive(Clap)]70pub struct OutputOpts {71 72 #[clap(long, short = 'o')]73 pub output_file: Option<PathBuf>,74 75 #[clap(long, short = 'c')]76 pub create_output_dirs: bool,77 78 #[clap(long, short = 'm')]79 pub multi: Option<PathBuf>,80}