1use std::path::PathBuf;23use clap::{Parser, ValueEnum};4use jrsonnet_evaluator::manifest::{5 JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,6};7use jrsonnet_stdlib::{TomlFormat, XmlJsonmlFormat, YamlFormat};89#[derive(Clone, Copy, ValueEnum)]10pub enum ManifestFormatName {11 12 String,13 Json,14 Yaml,15 Toml,16 XmlJsonml,17}1819#[derive(Parser)]20#[clap(next_help_heading = "MANIFESTIFICATION OUTPUT")]21pub struct ManifestOpts {22 23 24 25 #[clap(long, short = 'f')]26 format: Option<ManifestFormatName>,27 28 29 #[clap(long, short = 'S', conflicts_with = "format")]30 string: bool,31 32 #[clap(long, short = 'y', conflicts_with = "string")]33 yaml_stream: bool,34 35 36 37 38 #[clap(long)]39 line_padding: Option<usize>,40 41 #[cfg(feature = "exp-preserve-order")]42 #[clap(long)]43 pub preserve_order: bool,44}45impl ManifestOpts {46 pub fn manifest_format(&self) -> Box<dyn ManifestFormat> {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 let format = match self.format {53 Some(v) => v,54 None if self.yaml_stream => ManifestFormatName::Yaml,55 None => ManifestFormatName::Json,56 };57 match format {58 ManifestFormatName::String => Box::new(ToStringFormat),59 ManifestFormatName::Json => Box::new(JsonFormat::cli(60 self.line_padding.unwrap_or(3),61 #[cfg(feature = "exp-preserve-order")]62 preserve_order,63 )),64 ManifestFormatName::Yaml => Box::new(YamlFormat::cli(65 self.line_padding.unwrap_or(2),66 #[cfg(feature = "exp-preserve-order")]67 preserve_order,68 )),69 ManifestFormatName::Toml => Box::new(TomlFormat::cli(70 self.line_padding.unwrap_or(2),71 #[cfg(feature = "exp-preserve-order")]72 preserve_order,73 )),74 ManifestFormatName::XmlJsonml => Box::new(XmlJsonmlFormat::cli()),75 }76 };77 if self.yaml_stream {78 Box::new(YamlStreamFormat::cli(format))79 } else {80 format81 }82 }83}8485#[derive(Parser)]86pub struct OutputOpts {87 88 #[clap(long, short = 'o')]89 pub output_file: Option<PathBuf>,90 91 #[clap(long, short = 'c')]92 pub create_output_dirs: bool,93 94 #[clap(long, short = 'm')]95 pub multi: Option<PathBuf>,96}