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, 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 #[clap(long, short = 'f', default_value = "json")]23 format: ManifestFormatName,24 25 26 #[clap(long, short = 'S', conflicts_with = "format")]27 string: bool,28 29 #[clap(long, short = 'y', conflicts_with = "string")]30 yaml_stream: bool,31 32 33 #[clap(long)]34 line_padding: Option<usize>,35 36 #[cfg(feature = "exp-preserve-order")]37 #[clap(long)]38 pub preserve_order: bool,39}40impl ManifestOpts {41 pub fn manifest_format(&self) -> Box<dyn ManifestFormat> {42 let format: Box<dyn ManifestFormat> = if self.string {43 Box::new(StringFormat)44 } else {45 #[cfg(feature = "exp-preserve-order")]46 let preserve_order = self.preserve_order;47 match self.format {48 ManifestFormatName::String => Box::new(ToStringFormat),49 ManifestFormatName::Json => Box::new(JsonFormat::cli(50 self.line_padding.unwrap_or(3),51 #[cfg(feature = "exp-preserve-order")]52 preserve_order,53 )),54 ManifestFormatName::Yaml => Box::new(YamlFormat::cli(55 self.line_padding.unwrap_or(2),56 #[cfg(feature = "exp-preserve-order")]57 preserve_order,58 )),59 ManifestFormatName::Toml => Box::new(TomlFormat::cli(60 self.line_padding.unwrap_or(2),61 #[cfg(feature = "exp-preserve-order")]62 preserve_order,63 )),64 }65 };66 if self.yaml_stream {67 Box::new(YamlStreamFormat(format))68 } else {69 format70 }71 }72}7374#[derive(Parser)]75pub struct OutputOpts {76 77 #[clap(long, short = 'o')]78 pub output_file: Option<PathBuf>,79 80 #[clap(long, short = 'c')]81 pub create_output_dirs: bool,82 83 #[clap(long, short = 'm')]84 pub multi: Option<PathBuf>,85}