1use std::path::PathBuf;
2
3use clap::{Parser, ValueEnum};
4use jrsonnet_evaluator::manifest::{
5 JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,
6};
7use jrsonnet_stdlib::{IniFormat, TomlFormat, XmlJsonmlFormat, YamlFormat};
8
9#[derive(Clone, Copy, ValueEnum)]
10pub enum ManifestFormatName {
11 String,
13 Json,
14 Yaml,
15 Toml,
16 XmlJsonml,
17 Ini,
18}
19
20#[derive(Parser)]
21#[clap(next_help_heading = "MANIFESTIFICATION OUTPUT")]
22pub struct ManifestOpts {
23 #[clap(long, short = 'f')]
27 format: Option<ManifestFormatName>,
28 #[clap(long, short = 'S', conflicts_with = "format")]
31 string: bool,
32 #[clap(long, short = 'y', conflicts_with = "string")]
34 yaml_stream: bool,
35 #[clap(long)]
40 line_padding: Option<usize>,
41 #[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 format
86 }
87 }
88}
89
90#[derive(Parser)]
91pub struct OutputOpts {
92 #[clap(long, short = 'o')]
94 pub output_file: Option<PathBuf>,
95 #[clap(long, short = 'c')]
97 pub create_output_dirs: bool,
98 #[clap(long, short = 'm')]
100 pub multi: Option<PathBuf>,
101}