use super::{CliCommand, Invocation, flags, parse_json};
use crate::command::{RepoAdd, RepoIndex, RepoList, RepoRemove, RepoUpdate, Repository};
use crate::error::{Error, Result};
#[cfg(test)]
mod tests;
impl CliCommand for RepoAdd {
fn build(&self, inv: &mut Invocation) -> Result<()> {
if self.password.is_some() && self.username.is_none() {
return Err(Error::InvalidCommand(
"repo add reads the password from stdin only when a username is set".to_owned(),
));
}
inv.arg("repo");
inv.arg("add");
inv.arg(&self.name);
inv.arg(&self.url);
flags! { inv, self;
option("--username", username);
switch("--pass-credentials", pass_credentials);
switch("--force-update", force_update);
switch("--allow-deprecated-repos", allow_deprecated_repos);
option("--cert-file", cert_file);
option("--key-file", key_file);
option("--ca-file", ca_file);
switch("--insecure-skip-tls-verify", insecure_skip_tls_verify);
}
inv.timeout(self.timeout);
if let Some(password) = &self.password {
inv.arg("--password-stdin");
inv.stdin = Some(password.expose().as_bytes().to_vec());
}
Ok(())
}
fn parse(&self, _stdout: String) -> Result<()> {
Ok(())
}
}
impl CliCommand for RepoIndex {
fn build(&self, inv: &mut Invocation) -> Result<()> {
inv.arg("repo");
inv.arg("index");
inv.arg(&self.dir);
flags! { inv, self;
option("--url", url);
option("--merge", merge);
switch("--json", json);
}
Ok(())
}
fn parse(&self, _stdout: String) -> Result<()> {
Ok(())
}
}
impl CliCommand for RepoList {
fn build(&self, inv: &mut Invocation) -> Result<()> {
inv.arg("repo");
inv.arg("list");
inv.json_output();
Ok(())
}
fn parse(&self, stdout: String) -> Result<Vec<Repository>> {
parse_json("helm repo list", &stdout)
}
}
impl CliCommand for RepoRemove {
fn build(&self, inv: &mut Invocation) -> Result<()> {
if self.names.is_empty() {
return Err(Error::InvalidCommand(
"repo remove needs at least one repository".to_owned(),
));
}
inv.arg("repo");
inv.arg("remove");
for name in &self.names {
inv.arg(name);
}
Ok(())
}
fn parse(&self, _stdout: String) -> Result<()> {
Ok(())
}
}
impl CliCommand for RepoUpdate {
fn build(&self, inv: &mut Invocation) -> Result<()> {
inv.arg("repo");
inv.arg("update");
for name in &self.names {
inv.arg(name);
}
inv.timeout(self.timeout);
Ok(())
}
fn parse(&self, _stdout: String) -> Result<()> {
Ok(())
}
}