1use std::path::PathBuf;23use clap::{Parser, ValueEnum};4use jrsonnet_evaluator::{5 error::Result,6 manifest::{JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat},7 State,8};9use jrsonnet_stdlib::{TomlFormat, YamlFormat};1011use crate::ConfigureState;1213#[derive(Clone, ValueEnum)]14pub enum ManifestFormatName {15 16 String,17 Json,18 Yaml,19 Toml,20}2122#[derive(Parser)]23#[clap(next_help_heading = "MANIFESTIFICATION OUTPUT")]24pub struct ManifestOpts {25 26 #[clap(long, short = 'f', default_value = "json")]27 format: ManifestFormatName,28 29 30 #[clap(long, short = 'S', conflicts_with = "format")]31 string: bool,32 33 #[clap(long, short = 'y', conflicts_with = "string")]34 yaml_stream: bool,35 36 37 #[clap(long)]38 line_padding: Option<usize>,39 40 #[cfg(feature = "exp-preserve-order")]41 #[clap(long)]42 pub preserve_order: bool,43}44impl ConfigureState for ManifestOpts {45 type Guards = Box<dyn ManifestFormat>;46 fn configure(&self, _s: &State) -> Result<Self::Guards> {47 let format: Box<dyn ManifestFormat> = if self.string {48 Box::new(StringFormat)49 } else {50 #[cfg(feature = "exp-preserve-order")]51 let preserve_order = self.preserve_order;52 match self.format {53 ManifestFormatName::String => Box::new(ToStringFormat),54 ManifestFormatName::Json => Box::new(JsonFormat::cli(55 self.line_padding.unwrap_or(3),56 #[cfg(feature = "exp-preserve-order")]57 preserve_order,58 )),59 ManifestFormatName::Yaml => Box::new(YamlFormat::cli(60 self.line_padding.unwrap_or(2),61 #[cfg(feature = "exp-preserve-order")]62 preserve_order,63 )),64 ManifestFormatName::Toml => Box::new(TomlFormat::cli(65 self.line_padding.unwrap_or(2),66 #[cfg(feature = "exp-preserve-order")]67 preserve_order,68 )),69 }70 };71 Ok(if self.yaml_stream {72 Box::new(YamlStreamFormat(format))73 } else {74 format75 })76 }77}7879#[derive(Parser)]80pub struct OutputOpts {81 82 #[clap(long, short = 'o')]83 pub output_file: Option<PathBuf>,84 85 #[clap(long, short = 'c')]86 pub create_output_dirs: bool,87 88 #[clap(long, short = 'm')]89 pub multi: Option<PathBuf>,90}