Skip to main content

helm_schema_cli/cli/
output_args.rs

1use std::path::PathBuf;
2
3use clap::Args;
4
5use helm_schema::output::{
6    FetchPolicy, JsonOutputFormat, LoadBudget, OutputPipelineOptions, PolicyInputOptions,
7    ReferenceMode,
8};
9
10/// Destination, serialization, reference, and minimization options.
11#[derive(Args, Debug, Clone)]
12pub struct OutputArgs {
13    /// Optional output file; standard output is used when absent.
14    #[arg(short, long)]
15    pub output: Option<PathBuf>,
16
17    /// Write compact JSON output instead of the default pretty JSON.
18    #[arg(long)]
19    pub compact: bool,
20
21    /// Remove JSON Schema `description` annotations from the generated output.
22    ///
23    /// This is schema-aware: properties named `description` remain intact.
24    #[arg(long)]
25    pub strip_descriptions: bool,
26
27    /// Leave file/URL `$ref` strings in the generated schema as-is.
28    ///
29    /// By default, external refs are resolved into root-level `$defs` so the
30    /// output is self-contained while still sharing referenced schemas.
31    #[arg(long, conflicts_with = "inline_refs")]
32    pub keep_refs: bool,
33
34    /// Fully inline resolved file/URL `$ref`s instead of writing `$defs`.
35    #[arg(long)]
36    pub inline_refs: bool,
37
38    /// Keep repeated schema subtrees inline instead of interning them into
39    /// root-level `$defs`.
40    ///
41    /// Interning is an output-only transform over the final JSON Schema (it
42    /// does not participate in Helm template inference) and is on by default:
43    /// branch-scoped arms repeat large guard fragments, so interning keeps
44    /// big charts far below Helm's 5 MiB chart-file limit and speeds up every
45    /// downstream validator.
46    #[arg(long = "no-minimize", action = clap::ArgAction::SetFalse)]
47    pub minimize: bool,
48}
49
50impl OutputArgs {
51    pub(crate) fn policy_input_options(&self, fetch_policy: FetchPolicy) -> PolicyInputOptions {
52        PolicyInputOptions {
53            reference_mode: ReferenceMode::from_flags(self.keep_refs, self.inline_refs),
54            fetch_policy,
55            load_budget: LoadBudget::default(),
56        }
57    }
58
59    pub(crate) fn pipeline_options(&self) -> OutputPipelineOptions {
60        OutputPipelineOptions {
61            reference_mode: ReferenceMode::from_flags(self.keep_refs, self.inline_refs),
62            strip_descriptions: self.strip_descriptions,
63            minimize: self.minimize,
64        }
65    }
66
67    pub(crate) fn json_format(&self) -> JsonOutputFormat {
68        JsonOutputFormat::from_compact(self.compact)
69    }
70}