helm_rs/command/search.rs
1use serde::Deserialize;
2
3use crate::backend::Command;
4
5/// `helm search hub`: searches Artifact Hub (or another Monocular-compatible hub) over the
6/// network, requested as `-o json`. `--max-col-width` and `--list-repo-url` only shape the table,
7/// and the JSON always carries the repository, so they are not modelled.
8#[derive(Debug, Clone, Default, PartialEq, Eq, bon::Builder)]
9#[builder(on(String, into), on(bool, default))]
10pub struct SearchHub {
11 /// The search keyword (`KEYWORD`); Artifact Hub also accepts its rich query syntax.
12 pub keyword: Option<String>,
13 /// Flag `--endpoint`: the hub to query (Helm's default is `https://hub.helm.sh`).
14 pub endpoint: Option<String>,
15 /// Flag `--fail-on-no-result`: fail when nothing matches.
16 pub fail_on_no_result: bool,
17}
18
19/// One hub result (`hubChartElement` in `pkg/cmd/search_hub.go`, Helm v4.3.0).
20#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
21pub struct HubChart {
22 /// The package page on the hub.
23 pub url: String,
24 /// The latest chart version.
25 #[serde(default)]
26 pub version: String,
27 /// The latest application version.
28 #[serde(default)]
29 pub app_version: String,
30 /// The chart description.
31 #[serde(default)]
32 pub description: String,
33 /// The repository that hosts the chart.
34 pub repository: HubRepository,
35}
36
37/// The repository of a [`HubChart`] (`hubChartRepo`).
38#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
39pub struct HubRepository {
40 /// The repository URL.
41 #[serde(default)]
42 pub url: String,
43 /// The repository name on the hub.
44 #[serde(default)]
45 pub name: String,
46}
47
48impl Command for SearchHub {
49 type Output = Vec<HubChart>;
50}
51
52/// `helm search repo`: searches the cached indexes of the added repositories, requested as
53/// `-o json`. `--max-col-width` only shapes the table, so it is not modelled.
54#[derive(Debug, Clone, Default, PartialEq, Eq, bon::Builder)]
55#[builder(on(String, into), on(bool, default))]
56#[allow(clippy::struct_excessive_bools, reason = "one field per Helm flag")]
57pub struct SearchRepo {
58 /// The search keyword (`keyword`); empty lists every chart.
59 pub keyword: Option<String>,
60 /// Flag `--devel`: include pre-releases (the constraint `>0.0.0-0`); ignored with `version`.
61 pub devel: bool,
62 /// Flag `--fail-on-no-result`: fail when nothing matches.
63 pub fail_on_no_result: bool,
64 /// Flag `--regexp` (`-r`): treat the keyword as a regular expression.
65 pub regexp: bool,
66 /// Flag `--version`: a semantic version constraint.
67 pub version: Option<String>,
68 /// Flag `--versions` (`-l`): list every version of each chart, not only the newest.
69 pub versions: bool,
70}
71
72/// One repository search result (`repoChartElement` in `pkg/cmd/search_repo.go`, Helm v4.3.0).
73#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
74pub struct RepoChart {
75 /// The chart as `repository/chart`.
76 pub name: String,
77 /// The chart version.
78 #[serde(default)]
79 pub version: String,
80 /// The application version.
81 #[serde(default)]
82 pub app_version: String,
83 /// The chart description.
84 #[serde(default)]
85 pub description: String,
86}
87
88impl Command for SearchRepo {
89 type Output = Vec<RepoChart>;
90}