add no_uptodate option

This commit is contained in:
Nikolai Rodionov 2023-01-25 13:01:24 +01:00
parent e6e9c7b248
commit 6acf7a4dd1
2 changed files with 16 additions and 4 deletions

View File

@ -49,6 +49,9 @@ struct Args {
/// Set to true if you don't want to sync repositories /// Set to true if you don't want to sync repositories
#[clap(short, long, action, default_value_t = false)] #[clap(short, long, action, default_value_t = false)]
no_sync: bool, no_sync: bool,
/// Set to true if you don't wante to see up-to-date charts in the output
#[clap(long, action, default_value_t = true)]
no_uptodate: bool
} }
#[derive(Debug, Subcommand)] #[derive(Debug, Subcommand)]
@ -108,7 +111,7 @@ fn main() {
// Parse the helmfile // Parse the helmfile
// Handling the result // Handling the result
match handle_result(&result, args.outdated_fail, args.output) { match handle_result(&mut result, args.outdated_fail, args.output, args.no_uptodate) {
Ok(result) => { Ok(result) => {
if result { if result {
exit(1); exit(1);
@ -197,11 +200,15 @@ fn check_chart(result: &mut Vec<ExecResult>, local_chart: &types::HelmChart) ->
/// Handle result /// Handle result
fn handle_result( fn handle_result(
result: &Vec<ExecResult>, result: &mut Vec<ExecResult>,
outdated_fail: bool, outdated_fail: bool,
output_kind: Outputs, output_kind: Outputs,
no_uptodate: bool,
) -> Result<bool> { ) -> Result<bool> {
let mut failed = false; let mut failed = false;
if no_uptodate {
result.retain(|r| r.status != types::Status::Uptodate)
}
for r in result.clone() { for r in result.clone() {
match r.status { match r.status {
Status::Uptodate => info!("{} is up-to-date", r.name), Status::Uptodate => info!("{} is up-to-date", r.name),

View File

@ -16,7 +16,7 @@ pub(crate) struct HelmRepo {
pub(crate) url: String, pub(crate) url: String,
} }
#[derive(Clone, Serialize, Deserialize)] #[derive(Clone, Serialize, Deserialize, PartialEq, Eq)]
pub(crate) enum Status { pub(crate) enum Status {
Uptodate, Uptodate,
Outdated, Outdated,
@ -42,7 +42,12 @@ pub(crate) struct ExecResult {
} }
impl ExecResult { impl ExecResult {
pub(crate) fn new(name: String, latest_version: String, current_version: String, status: Status) -> Self { pub(crate) fn new(
name: String,
latest_version: String,
current_version: String,
status: Status,
) -> Self {
Self { Self {
name, name,
latest_version, latest_version,