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