implement option for quiet output
This commit is contained in:
parent
f8453e4a0a
commit
2b59bdf961
28
src/lib.rs
28
src/lib.rs
@ -131,17 +131,13 @@ pub enum OutputStyle {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Options<'a> {
|
pub struct Options<'a> {
|
||||||
pub style: OutputStyle,
|
style: OutputStyle,
|
||||||
pub load_paths: Vec<&'a Path>,
|
load_paths: Vec<&'a Path>,
|
||||||
pub allows_charset: bool,
|
allows_charset: bool,
|
||||||
pub unicode_error_messages: bool,
|
unicode_error_messages: bool,
|
||||||
pub quiet: bool,
|
quiet: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// `load_paths` - list of paths/files to check for imports for more information see the docs:
|
|
||||||
/// - <https://sass-lang.com/documentation/at-rules/import#finding-the-file>
|
|
||||||
/// - <https://sass-lang.com/documentation/at-rules/import#load-paths>
|
|
||||||
impl<'a> Default for Options<'a> {
|
impl<'a> Default for Options<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@ -160,7 +156,8 @@ impl<'a> Options<'a> {
|
|||||||
/// `grass` currently offers 2 different output styles
|
/// `grass` currently offers 2 different output styles
|
||||||
///
|
///
|
||||||
/// - `OutputStyle::Expanded` writes each selector and declaration on its own line.
|
/// - `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.
|
/// By default, output is expanded.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
@ -170,6 +167,13 @@ impl<'a> Options<'a> {
|
|||||||
self
|
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]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn quiet(mut self, quiet: bool) -> Self {
|
pub fn quiet(mut self, quiet: bool) -> Self {
|
||||||
@ -177,6 +181,9 @@ impl<'a> Options<'a> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `load_paths` - list of paths/files to check for imports for more information see the docs:
|
||||||
|
/// - <https://sass-lang.com/documentation/at-rules/import#finding-the-file>
|
||||||
|
/// - <https://sass-lang.com/documentation/at-rules/import#load-paths>
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn load_path(mut self, path: &'a Path) -> Self {
|
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.load_paths.extend_from_slice(paths);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn allows_charset(mut self, allows_charset: bool) -> Self {
|
pub fn allows_charset(mut self, allows_charset: bool) -> Self {
|
||||||
|
@ -848,6 +848,9 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
fn debug(&self, message: &Spanned<Cow<'a, str>>) {
|
fn debug(&self, message: &Spanned<Cow<'a, str>>) {
|
||||||
|
if self.options.quiet {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let loc = self.map.look_up_span(message.span);
|
let loc = self.map.look_up_span(message.span);
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{}:{} Debug: {}",
|
"{}:{} Debug: {}",
|
||||||
@ -858,6 +861,9 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn warn(&self, message: &Spanned<Cow<'a, str>>) {
|
fn warn(&self, message: &Spanned<Cow<'a, str>>) {
|
||||||
|
if self.options.quiet {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let loc = self.map.look_up_span(message.span);
|
let loc = self.map.look_up_span(message.span);
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Warning: {}\n {} {}:{} root stylesheet",
|
"Warning: {}\n {} {}:{} root stylesheet",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user