just/src/warning.rs

49 lines
1.1 KiB
Rust
Raw Normal View History

use crate::common::*;
2021-06-08 01:01:27 -07:00
#[derive(Clone, Debug, PartialEq)]
pub(crate) enum Warning {
2021-03-30 17:59:15 -07:00
// Remove this on 2021-07-01.
#[allow(dead_code)]
DotenvLoad,
}
impl Warning {
fn context(&self) -> Option<&Token> {
match self {
Self::DotenvLoad => None,
}
}
pub(crate) fn write(&self, w: &mut dyn Write, color: Color) -> io::Result<()> {
let warning = color.warning();
let message = color.message();
write!(w, "{} {}", warning.paint("warning:"), message.prefix())?;
match self {
Self::DotenvLoad => {
#[rustfmt::skip]
write!(w, "\
A `.env` file was found and loaded, but this behavior will change in the future.
To silence this warning and continue loading `.env` files, add:
set dotenv-load := true
To silence this warning and stop loading `.env` files, add:
set dotenv-load := false
See https://github.com/casey/just/issues/469 for more details.")?;
},
}
writeln!(w, "{}", message.suffix())?;
if let Some(token) = self.context() {
token.write_context(w, warning)?;
}
Ok(())
}
}