From 2b59bdf96196c3df53735c8de1ca47215fcddbb7 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Wed, 15 Jul 2020 13:40:39 -0400 Subject: [PATCH] implement option for quiet output --- src/lib.rs | 28 ++++++++++++++++++---------- src/parse/mod.rs | 6 ++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bbf8e98..2e56b76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,17 +131,13 @@ pub enum OutputStyle { #[derive(Debug)] pub struct Options<'a> { - pub style: OutputStyle, - pub load_paths: Vec<&'a Path>, - pub allows_charset: bool, - pub unicode_error_messages: bool, - pub quiet: bool, + style: OutputStyle, + load_paths: Vec<&'a Path>, + allows_charset: bool, + unicode_error_messages: bool, + quiet: bool, } -/// -/// `load_paths` - list of paths/files to check for imports for more information see the docs: -/// - -/// - impl<'a> Default for Options<'a> { #[inline] fn default() -> Self { @@ -160,7 +156,8 @@ impl<'a> Options<'a> { /// `grass` currently offers 2 different output styles /// /// - `OutputStyle::Expanded` writes each selector and declaration on its own line. - /// - `OutputStyle::Compressed` removes as many extra characters as possible, and writes the entire stylesheet on a single line. + /// - `OutputStyle::Compressed` removes as many extra characters as possible, + /// and writes the entire stylesheet on a single line. /// /// By default, output is expanded. #[must_use] @@ -170,6 +167,13 @@ impl<'a> Options<'a> { self } + /// This flag tells Sass not to emit any warnings + /// when compiling. By default, Sass emits warnings + /// when deprecated features are used or when the + /// `@warn` rule is encountered. It also silences the + /// `@debug` rule. + /// + /// By default, this value is `false` and warnings are emitted. #[must_use] #[inline] pub fn quiet(mut self, quiet: bool) -> Self { @@ -177,6 +181,9 @@ impl<'a> Options<'a> { self } + /// `load_paths` - list of paths/files to check for imports for more information see the docs: + /// - + /// - #[must_use] #[inline] pub fn load_path(mut self, path: &'a Path) -> Self { @@ -191,6 +198,7 @@ impl<'a> Options<'a> { self.load_paths.extend_from_slice(paths); self } + #[must_use] #[inline] pub fn allows_charset(mut self, allows_charset: bool) -> Self { diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 50d22f1..3f99797 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -848,6 +848,9 @@ impl<'a> Parser<'a> { impl<'a> Parser<'a> { fn debug(&self, message: &Spanned>) { + if self.options.quiet { + return; + } let loc = self.map.look_up_span(message.span); eprintln!( "{}:{} Debug: {}", @@ -858,6 +861,9 @@ impl<'a> Parser<'a> { } fn warn(&self, message: &Spanned>) { + if self.options.quiet { + return; + } let loc = self.map.look_up_span(message.span); eprintln!( "Warning: {}\n {} {}:{} root stylesheet",