1use std::path::PathBuf;23use clap::{Parser, ValueEnum};4use jrsonnet_evaluator::{5 error::Result,6 manifest::{JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat},7 State,8};9use jrsonnet_stdlib::{TomlFormat, YamlFormat};1011#[derive(Clone, ValueEnum)]12pub enum ManifestFormatName {13 14 String,15 Json,16 Yaml,17 Toml,18}1920#[derive(Parser)]21#[clap(next_help_heading = "MANIFESTIFICATION OUTPUT")]22pub struct ManifestOpts {23 24 #[clap(long, short = 'f', default_value = "json")]25 format: 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 #[clap(long)]36 line_padding: Option<usize>,37 38 #[cfg(feature = "exp-preserve-order")]39 #[clap(long)]40 pub preserve_order: bool,41}42impl ManifestOpts {43 pub fn manifest_format(&self) -> Box<dyn ManifestFormat> {44 let format: Box<dyn ManifestFormat> = if self.string {45 Box::new(StringFormat)46 } else {47 #[cfg(feature = "exp-preserve-order")]48 let preserve_order = self.preserve_order;49 match self.format {50 ManifestFormatName::String => Box::new(ToStringFormat),51 ManifestFormatName::Json => Box::new(JsonFormat::cli(52 self.line_padding.unwrap_or(3),53 #[cfg(feature = "exp-preserve-order")]54 preserve_order,55 )),56 ManifestFormatName::Yaml => Box::new(YamlFormat::cli(57 self.line_padding.unwrap_or(2),58 #[cfg(feature = "exp-preserve-order")]59 preserve_order,60 )),61 ManifestFormatName::Toml => Box::new(TomlFormat::cli(62 self.line_padding.unwrap_or(2),63 #[cfg(feature = "exp-preserve-order")]64 preserve_order,65 )),66 }67 };68 if self.yaml_stream {69 Box::new(YamlStreamFormat(format))70 } else {71 format72 }73 }74}7576#[derive(Parser)]77pub struct OutputOpts {78 79 #[clap(long, short = 'o')]80 pub output_file: Option<PathBuf>,81 82 #[clap(long, short = 'c')]83 pub create_output_dirs: bool,84 85 #[clap(long, short = 'm')]86 pub multi: Option<PathBuf>,87}