Adding in --quiet flag to suppress warnings

master
Pauan 6 years ago
parent 439e523192
commit a8f4ddbe05
  1. 6
      src/lib.rs
  2. 6
      src/main.rs
  3. 27
      src/progressbar.rs

@ -47,7 +47,7 @@ pub mod wasm_opt;
use progressbar::ProgressOutput; use progressbar::ProgressOutput;
/// The global progress bar and user-facing message output. /// The global progress bar and user-facing message output.
pub static PBAR: ProgressOutput = ProgressOutput; pub static PBAR: ProgressOutput = ProgressOutput::new();
/// 📦 ✨ pack and publish your wasm! /// 📦 ✨ pack and publish your wasm!
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
@ -59,4 +59,8 @@ pub struct Cli {
/// Log verbosity is based off the number of v used /// Log verbosity is based off the number of v used
#[structopt(long = "verbose", short = "v", parse(from_occurrences))] #[structopt(long = "verbose", short = "v", parse(from_occurrences))]
pub verbosity: u8, pub verbosity: u8,
#[structopt(long = "quiet")]
/// Silences wasm-pack warnings.
pub quiet: bool,
} }

@ -76,6 +76,12 @@ fn run() -> Result<(), failure::Error> {
} }
let args = Cli::from_args(); let args = Cli::from_args();
if args.quiet {
PBAR.set_quiet(true);
log::set_max_level(log::LevelFilter::Error);
}
run_wasm_pack(args.cmd)?; run_wasm_pack(args.cmd)?;
if let Ok(wasm_pack_version) = wasm_pack_version.try_recv() { if let Ok(wasm_pack_version) = wasm_pack_version.try_recv() {

@ -1,25 +1,47 @@
//! Fancy progress bar functionality. //! Fancy progress bar functionality.
use std::sync::atomic::{AtomicBool, Ordering};
use console::style; use console::style;
use emoji; use emoji;
/// Synchronized progress bar and status message printing. /// Synchronized progress bar and status message printing.
pub struct ProgressOutput; pub struct ProgressOutput {
quiet: AtomicBool,
}
impl ProgressOutput { impl ProgressOutput {
/// Returns a new ProgressOutput
pub const fn new() -> Self {
Self {
quiet: AtomicBool::new(false),
}
}
/// Print the given message. /// Print the given message.
fn message(&self, message: &str) { fn message(&self, message: &str) {
eprintln!("{}", message); eprintln!("{}", message);
} }
fn quiet(&self) -> bool {
self.quiet.load(Ordering::SeqCst)
}
/// Sets whether it should silence warnings or not
pub fn set_quiet(&self, quiet: bool) {
self.quiet.store(quiet, Ordering::SeqCst);
}
/// Add an informational message. /// Add an informational message.
pub fn info(&self, message: &str) { pub fn info(&self, message: &str) {
if !self.quiet() {
let info = format!("{}: {}", style("[INFO]").bold().dim(), message,); let info = format!("{}: {}", style("[INFO]").bold().dim(), message,);
self.message(&info); self.message(&info);
} }
}
/// Add a warning message. /// Add a warning message.
pub fn warn(&self, message: &str) { pub fn warn(&self, message: &str) {
if !self.quiet() {
let warn = format!( let warn = format!(
"{} {}: {}", "{} {}: {}",
emoji::WARN, emoji::WARN,
@ -28,6 +50,7 @@ impl ProgressOutput {
); );
self.message(&warn); self.message(&warn);
} }
}
/// Add an error message. /// Add an error message.
pub fn error(&self, message: &str) { pub fn error(&self, message: &str) {
@ -43,6 +66,6 @@ impl ProgressOutput {
impl Default for ProgressOutput { impl Default for ProgressOutput {
fn default() -> Self { fn default() -> Self {
ProgressOutput ProgressOutput::new()
} }
} }

Loading…
Cancel
Save