@@ -1,38 +1,42 @@
11// TODO: Re-enable generation of shell completion files (below) when clap 3 is out.
22// For more details, see https://github.com/sharkdp/bat/issues/372
33
4−#[macro_use]
5−extern crate lazy_static;
6−extern crate liquid;
7−
8−use std::error::Error;
9−use std::fs;
10−use std::path::Path;
11−
12−// Read environment variables.
13−lazy_static! {
14− pub static ref PROJECT_NAME: &'static str = option_env!("PROJECT_NAME").unwrap_or("bat");
15− pub static ref PROJECT_VERSION: &'static str = option_env!("CARGO_PKG_VERSION").unwrap();
16− pub static ref EXECUTABLE_NAME: &'static str = option_env!("PROJECT_EXECUTABLE")
17− .or(option_env!("PROJECT_NAME"))
18− .unwrap_or("bat");
19−}
20−
21−/// Generates a file from a liquid template.
22−fn template(
23− variables: &liquid::Object,
24− in_file: &str,
25− out_file: impl AsRef<Path>,
26−) -> Result<(), Box<dyn Error>> {
27− let template = liquid::ParserBuilder::with_stdlib()
28− .build()?
29− .parse(&fs::read_to_string(in_file)?)?;
30−
31− fs::write(out_file, template.render(variables)?)?;
32− Ok(())
33−}
4+// For bat-as-a-library, no build script is required. The build script is for
5+// the manpage and completions, which are only relevant to the bat application.
6+#[cfg(not(feature = "application"))]
7+fn main() {}
8+
9+#[cfg(feature = "application")]
10+fn main() -> Result<(), Box<dyn std::error::Error>> {
11+ use std::error::Error;
12+ use std::fs;
13+ use std::path::Path;
14+
15+ use lazy_static::lazy_static;
16+
17+ // Read environment variables.
18+ lazy_static! {
19+ static ref PROJECT_NAME: &'static str = option_env!("PROJECT_NAME").unwrap_or("bat");
20+ static ref PROJECT_VERSION: &'static str = option_env!("CARGO_PKG_VERSION").unwrap();
21+ static ref EXECUTABLE_NAME: &'static str = option_env!("PROJECT_EXECUTABLE")
22+ .or(option_env!("PROJECT_NAME"))
23+ .unwrap_or("bat");
24+ }
25+
26+ /// Generates a file from a liquid template.
27+ fn template(
28+ variables: &liquid::Object,
29+ in_file: &str,
30+ out_file: impl AsRef<Path>,
31+ ) -> Result<(), Box<dyn Error>> {
32+ let template = liquid::ParserBuilder::with_stdlib()
33+ .build()?
34+ .parse(&fs::read_to_string(in_file)?)?;
35+
36+ fs::write(out_file, template.render(variables)?)?;
37+ Ok(())
38+ }
3439
35−fn main() -> Result<(), Box<dyn Error>> {
3640 let variables = liquid::object!({
3741 "PROJECT_NAME": PROJECT_NAME.to_owned(),
3842 "PROJECT_EXECUTABLE": EXECUTABLE_NAME.to_owned(),