Skip to content

Commit

Permalink
added verbose flag, printing when no matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramilito committed Sep 3, 2022
1 parent 6f8d351 commit 36b9965
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ pub fn pretty_print_path(string: String) {
.unwrap();
}

pub fn pretty_print_info(string: String) {
PrettyPrinter::new()
.input(Input::from_bytes(&string.as_bytes()))
.header(false)
.grid(false)
.language("yaml")
.theme("OneHalfDark")
.print()
.unwrap();
}

pub fn pretty_print(string: String) {
PrettyPrinter::new()
.input(
Expand Down
18 changes: 14 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ mod commands;
mod settings;

use clap::Parser;
use commands::{get_build, get_diff, pretty_print, pretty_print_path};
use commands::{get_build, get_diff, pretty_print, pretty_print_info, pretty_print_path};
use serde::Deserialize;
use serde_yaml::Value;
use settings::Settings;
use std::io::{self, Write};

#[derive(Parser)]
#[derive(Debug, Parser)]
#[clap(author, version, about, long_about = None)]
pub struct Cli {
#[clap(short, long, value_parser)]
env: Option<String>,
#[clap(short, long, action)]
verbose: bool,
}

fn main() -> Result<(), io::Error> {
Expand All @@ -39,10 +41,18 @@ fn main() -> Result<(), io::Error> {
.unwrap();

let diff = diff.wait_with_output().unwrap();

let string = String::from_utf8(diff.stdout.to_owned()).unwrap();

pretty_print(string);
if string.len() > 0 {
pretty_print(string);
} else if args.verbose {
pretty_print_info(format!(
"No changes in: {:?} {:?} {:?}\n",
v["apiVersion"].as_str().unwrap(),
v["kind"].as_str().unwrap(),
v["metadata"]["name"].as_str().unwrap()
));
}
}
}

Expand Down

0 comments on commit 36b9965

Please sign in to comment.