diff --git a/hipcheck/src/cli.rs b/hipcheck/src/cli.rs index a7b50b10..e22dd730 100644 --- a/hipcheck/src/cli.rs +++ b/hipcheck/src/cli.rs @@ -17,7 +17,7 @@ use crate::target::{ use clap::{Parser as _, ValueEnum}; use hipcheck_macros as hc; use pathbuf::pathbuf; -use std::{env, path::{Path, PathBuf}}; +use std::path::{Path, PathBuf}; use url::Url; /// Automatated supply chain risk assessment of software packages. @@ -324,7 +324,10 @@ impl CliConfig { config: dirs::home_dir().map(|dir| pathbuf![&dir, "hipcheck", "config"]), data: dirs::home_dir().map(|dir| pathbuf![&dir, "hipcheck", "data"]), cache: dirs::home_dir().map(|dir| pathbuf![&dir, "hipcheck", "cache"]), - policy: env::current_dir().ok().map(|dir| pathbuf![&dir, "Hipcheck.kdl"]), + // TODO: currently if this is set, then when running `hc check`, it errors out + // because policy files are not yet supported + // policy: env::current_dir().ok().map(|dir| pathbuf![&dir, "Hipcheck.kdl"]), + policy: None, }, ..Default::default() } diff --git a/hipcheck/src/session/session.rs b/hipcheck/src/session/session.rs index 44190ca4..37b6f528 100644 --- a/hipcheck/src/session/session.rs +++ b/hipcheck/src/session/session.rs @@ -290,7 +290,6 @@ fn load_target(seed: &TargetSeed, home: &Path) -> Result { // Set the phase to tick steadily 10 times a second. phase.enable_steady_tick(Duration::from_millis(100)); let target = resolve_target(seed, &phase, home)?; - println!("TARGET: {target:?}"); phase.finish_successful(); Ok(target) diff --git a/hipcheck/src/shell.rs b/hipcheck/src/shell.rs index db2a8257..a2fb6720 100644 --- a/hipcheck/src/shell.rs +++ b/hipcheck/src/shell.rs @@ -224,7 +224,12 @@ impl Shell { /// Print "Analysing {source}" with the proper color/styling. pub fn print_prelude(source: impl AsRef) { - macros::println!("{:>LEFT_COL_WIDTH$} {}", Title::Analyzing, source.as_ref()); + match Shell::get_verbosity() { + Verbosity::Normal => { + macros::println!("{:>LEFT_COL_WIDTH$} {}", Title::Analyzing, source.as_ref()); + } + Verbosity::Quiet | Verbosity::Silent => {} + } } /// Print a hipcheck [Error]. Human readable errors will go to the standard error, JSON will go to the standard output. diff --git a/hipcheck/src/shell/spinner_phase.rs b/hipcheck/src/shell/spinner_phase.rs index c3359e88..adc65150 100644 --- a/hipcheck/src/shell/spinner_phase.rs +++ b/hipcheck/src/shell/spinner_phase.rs @@ -4,9 +4,9 @@ use crate::shell::Title; -use super::{Shell, HOUR_GLASS, LEFT_COL_WIDTH, ROCKET_SHIP}; +use super::{verbosity::Verbosity, Shell, HOUR_GLASS, LEFT_COL_WIDTH, ROCKET_SHIP}; use console::style; -use indicatif::{HumanDuration, ProgressBar, ProgressStyle}; +use indicatif::{HumanDuration, ProgressBar, ProgressDrawTarget, ProgressStyle}; use std::{ fmt::Display, sync::{Arc, OnceLock}, @@ -41,11 +41,18 @@ impl SpinnerPhase { /// /// The phase will remain in the "starting..." state until incremented. pub fn start(name: impl Into>) -> Self { - // Create the spinner progress bar with our styling. - let bar = ProgressBar::new_spinner().with_style(spinner_style().clone()); - - // Add to the global shell. - Shell::progress_bars().add(bar.clone()); + // Add to the global shell, only if Verbosity::Normal + let bar = match Shell::get_verbosity() { + Verbosity::Quiet | Verbosity::Silent => { + // ProgressBar::new_spinner internally assumes data will be written to stderr, which is not what is wanted for Silent/Quiet + ProgressBar::with_draw_target(None, ProgressDrawTarget::hidden()) + } + Verbosity::Normal => { + let bar = ProgressBar::new_spinner().with_style(spinner_style().clone()); + Shell::progress_bars().add(bar.clone()); + bar + } + }; let name = name.into(); @@ -91,13 +98,17 @@ impl SpinnerPhase { /// Finishes this spinner, leaving it in the terminal with an updated "done" message. pub fn finish_successful(&self) { - super::macros::println!( - "{:>LEFT_COL_WIDTH$} {} ({})", - Title::Done, - self.name, - style(HumanDuration(self.elapsed())).bold() - ); - + match Shell::get_verbosity() { + Verbosity::Normal => { + super::macros::println!( + "{:>LEFT_COL_WIDTH$} {} ({})", + Title::Done, + self.name, + style(HumanDuration(self.elapsed())).bold() + ); + } + Verbosity::Quiet | Verbosity::Silent => {} + } self.bar.finish_and_clear() } diff --git a/hipcheck/src/source/git.rs b/hipcheck/src/source/git.rs index bdc28f6e..8cd2601e 100644 --- a/hipcheck/src/source/git.rs +++ b/hipcheck/src/source/git.rs @@ -1,6 +1,7 @@ //! Git related types and implementations for pulling/cloning source repos. use crate::error::{Error as HcError, Result as HcResult}; +use crate::shell::verbosity::Verbosity; use crate::{ context::Context, shell::{progress_phase::ProgressPhase, Shell}, @@ -25,27 +26,33 @@ fn make_remote_callbacks() -> RemoteCallbacks<'static> { // Messages from the remote ("Counting objects" etc) are sent over the sideband. // This involves clearing and replacing the line -- use console to do this effectively. - callbacks.sideband_progress(move |msg: &[u8]| { - Shell::in_suspend(|| { - // use the standard output. - let mut term = Term::stdout(); - // Crash on errors here, since they should be relatively uncommon. - term.clear_line().expect("clear line on standard output"); + match Shell::get_verbosity() { + Verbosity::Normal => { + callbacks.sideband_progress(move |msg: &[u8]| { + Shell::in_suspend(|| { + // use the standard output. + let mut term = Term::stdout(); - write!(&mut term, "remote: {}", String::from_utf8_lossy(msg)) - .expect("wrote to standard output"); + // Crash on errors here, since they should be relatively uncommon. + term.clear_line().expect("clear line on standard output"); - term.flush().expect("flushed standard output"); - }); + write!(&mut term, "remote: {}", String::from_utf8_lossy(msg)) + .expect("wrote to standard output"); - true - }); + term.flush().expect("flushed standard output"); + }); + + true + }); + } + Verbosity::Quiet | Verbosity::Silent => {} + } callbacks.transfer_progress(move |prog: Progress| { if prog.received_objects() > 0 { let phase = transfer_phase.get_or_init(|| { - ProgressPhase::start(prog.total_objects() as u64, "(git) recieving objects") + ProgressPhase::start(prog.total_objects() as u64, "(git) receiving objects") }); phase.set_position(prog.received_objects() as u64);