1use std::fmt;
7use std::path::PathBuf;
8
9use crate::command::builder_collections;
10
11#[derive(Clone, PartialEq, Eq)]
13pub struct Secret(String);
14
15impl Secret {
16 #[must_use]
18 pub fn expose(&self) -> &str {
19 &self.0
20 }
21}
22
23impl From<String> for Secret {
24 fn from(value: String) -> Self {
25 Self(value)
26 }
27}
28
29impl From<&str> for Secret {
30 fn from(value: &str) -> Self {
31 Self(value.to_owned())
32 }
33}
34
35impl fmt::Debug for Secret {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 f.write_str("Secret(<redacted>)")
38 }
39}
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub enum Color {
44 Never,
46 Auto,
48 Always,
50}
51
52impl Color {
53 #[must_use]
55 pub fn as_str(self) -> &'static str {
56 match self {
57 Self::Never => "never",
58 Self::Auto => "auto",
59 Self::Always => "always",
60 }
61 }
62}
63
64#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66pub enum Driver {
67 Secret,
69 ConfigMap,
71 Memory,
73 Sql,
75}
76
77impl Driver {
78 #[must_use]
80 pub fn as_str(self) -> &'static str {
81 match self {
82 Self::Secret => "secret",
83 Self::ConfigMap => "configmap",
84 Self::Memory => "memory",
85 Self::Sql => "sql",
86 }
87 }
88}
89
90#[derive(Debug, Clone, Default, PartialEq, bon::Builder)]
95#[builder(
96 on(String, into),
97 on(PathBuf, into),
98 on(Secret, into),
99 on(bool, default)
100)]
101pub struct GlobalOptions {
102 #[builder(field)]
104 pub kube_as_group: Vec<String>,
105 #[builder(field)]
107 pub memory_driver_data: Vec<PathBuf>,
108 pub kubeconfig: Option<PathBuf>,
111 pub kube_context: Option<String>,
113 pub namespace: Option<String>,
115 pub kube_apiserver: Option<String>,
117 pub kube_as_user: Option<String>,
119 pub kube_ca_file: Option<PathBuf>,
121 pub kube_insecure_skip_tls_verify: bool,
123 pub kube_tls_server_name: Option<String>,
125 pub kube_token: Option<Secret>,
127 pub qps: Option<f32>,
129 pub burst_limit: Option<i32>,
131 pub debug: bool,
133 pub color: Option<Color>,
135 pub registry_config: Option<PathBuf>,
137 pub repository_config: Option<PathBuf>,
139 pub repository_cache: Option<PathBuf>,
141 pub content_cache: Option<PathBuf>,
143 pub cache_home: Option<PathBuf>,
145 pub config_home: Option<PathBuf>,
147 pub data_home: Option<PathBuf>,
149 pub driver: Option<Driver>,
151 pub driver_sql_connection_string: Option<Secret>,
153 pub max_history: Option<u32>,
155 pub plugins: Option<PathBuf>,
157 pub no_plugins: bool,
159}
160
161builder_collections! {
162 GlobalOptionsBuilder, global_options_builder;
163 vec kube_as_group / add_kube_as_group: String, "repeated flag `--kube-as-group`", "the groups to impersonate";
164 vec memory_driver_data / memory_driver_file: PathBuf, "`HELM_MEMORY_DRIVER_DATA` files", "the files the memory driver loads";
165}
166
167#[cfg(test)]
168mod tests;