1use std::path::PathBuf;23use clap::{Parser, ValueEnum};4use jrsonnet_evaluator::manifest::{5 JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,6};7use jrsonnet_stdlib::{IniFormat, TomlFormat, XmlJsonmlFormat, YamlFormat};89#[derive(Clone, Copy, ValueEnum)]10pub enum ManifestFormatName {11 12 String,13 Json,14 Yaml,15 Toml,16 XmlJsonml,17 Ini,18}1920#[derive(Parser)]21#[clap(next_help_heading = "MANIFESTIFICATION OUTPUT")]22pub struct ManifestOpts {23 24 25 26 #[clap(long, short = 'f')]27 format: Option<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 38 39 #[clap(long)]40 line_padding: Option<usize>,41 42 #[clap(long)]43 pub no_trailing_newline: bool,44 45 #[cfg(feature = "exp-preserve-order")]46 #[clap(long)]47 pub preserve_order: bool,48}49impl ManifestOpts {50 pub fn manifest_format(&self) -> Box<dyn ManifestFormat> {51 let format: Box<dyn ManifestFormat> = if self.string {52 Box::new(StringFormat)53 } else {54 #[cfg(feature = "exp-preserve-order")]55 let preserve_order = self.preserve_order;56 let format = match self.format {57 Some(v) => v,58 None if self.yaml_stream => ManifestFormatName::Yaml,59 None => ManifestFormatName::Json,60 };61 match format {62 ManifestFormatName::String => Box::new(ToStringFormat),63 ManifestFormatName::Json => Box::new(JsonFormat::cli(64 self.line_padding.unwrap_or(3),65 #[cfg(feature = "exp-preserve-order")]66 preserve_order,67 )),68 ManifestFormatName::Yaml => Box::new(YamlFormat::cli(69 self.line_padding.unwrap_or(2),70 #[cfg(feature = "exp-preserve-order")]71 preserve_order,72 )),73 ManifestFormatName::Toml => Box::new(TomlFormat::cli(74 self.line_padding.unwrap_or(2),75 #[cfg(feature = "exp-preserve-order")]76 preserve_order,77 )),78 ManifestFormatName::XmlJsonml => Box::new(XmlJsonmlFormat::cli()),79 ManifestFormatName::Ini => Box::new(IniFormat::cli(80 #[cfg(feature = "exp-preserve-order")]81 preserve_order,82 )),83 }84 };85 if self.yaml_stream {86 Box::new(YamlStreamFormat::cli(format))87 } else {88 format89 }90 }91}9293#[derive(Parser)]94pub struct OutputOpts {95 96 #[clap(long, short = 'o')]97 pub output_file: Option<PathBuf>,98 99 #[clap(long, short = 'c')]100 pub create_output_dirs: bool,101 102 #[clap(long, short = 'm')]103 pub multi: Option<PathBuf>,104}