Skip to main content

helm_schema_cli/cli/
output_args.rs

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