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 #[cfg(feature = "exp-preserve-order")]43 #[clap(long)]44 pub preserve_order: bool,45}46impl ManifestOpts {47 pub fn manifest_format(&self) -> Box<dyn ManifestFormat> {48 let format: Box<dyn ManifestFormat> = if self.string {49 Box::new(StringFormat)50 } else {51 #[cfg(feature = "exp-preserve-order")]52 let preserve_order = self.preserve_order;53 let format = match self.format {54 Some(v) => v,55 None if self.yaml_stream => ManifestFormatName::Yaml,56 None => ManifestFormatName::Json,57 };58 match format {59 ManifestFormatName::String => Box::new(ToStringFormat),60 ManifestFormatName::Json => Box::new(JsonFormat::cli(61 self.line_padding.unwrap_or(3),62 #[cfg(feature = "exp-preserve-order")]63 preserve_order,64 )),65 ManifestFormatName::Yaml => Box::new(YamlFormat::cli(66 self.line_padding.unwrap_or(2),67 #[cfg(feature = "exp-preserve-order")]68 preserve_order,69 )),70 ManifestFormatName::Toml => Box::new(TomlFormat::cli(71 self.line_padding.unwrap_or(2),72 #[cfg(feature = "exp-preserve-order")]73 preserve_order,74 )),75 ManifestFormatName::XmlJsonml => Box::new(XmlJsonmlFormat::cli()),76 ManifestFormatName::Ini => Box::new(IniFormat::cli(77 #[cfg(feature = "exp-preserve-order")]78 preserve_order,79 )),80 }81 };82 if self.yaml_stream {83 Box::new(YamlStreamFormat::cli(format))84 } else {85 format86 }87 }88}8990#[derive(Parser)]91pub struct OutputOpts {92 93 #[clap(long, short = 'o')]94 pub output_file: Option<PathBuf>,95 96 #[clap(long, short = 'c')]97 pub create_output_dirs: bool,98 99 #[clap(long, short = 'm')]100 pub multi: Option<PathBuf>,101}