on 7ca73c2 help sign in
bat/build.rs
93 lines 2.5 kB history raw
1// TODO: Re-enable generation of shell completion files (below) when clap 3 is out.
2// For more details, see https://github.com/sharkdp/bat/issues/372
4#[macro_use]
5extern crate lazy_static;
6extern crate liquid;
8use std::error::Error;
9use std::fs;
11// Read environment variables.
12lazy_static! {
13 pub static ref PROJECT_NAME: &'static str = option_env!("PROJECT_NAME").unwrap_or("bat");
14 pub static ref PROJECT_VERSION: &'static str = option_env!("CARGO_PKG_VERSION").unwrap();
15 pub static ref EXECUTABLE_NAME: &'static str = option_env!("PROJECT_EXECUTABLE")
16 .or(option_env!("PROJECT_NAME"))
17 .unwrap_or("bat");
20fn init_template() -> liquid::value::Object {
21 let mut globals = liquid::value::Object::new();
23 globals.insert(
24 "PROJECT_NAME".into(),
25 liquid::value::Value::scalar(PROJECT_NAME.to_owned()),
26 );
28 globals.insert(
29 "PROJECT_EXECUTABLE".into(),
30 liquid::value::Value::scalar(EXECUTABLE_NAME.to_owned()),
31 );
33 globals.insert(
34 "PROJECT_VERSION".into(),
35 liquid::value::Value::scalar(PROJECT_VERSION.to_owned()),
36 );
38 globals
41/// Generates a file from a liquid template.
42fn template(
43 variables: &liquid::value::Object,
44 in_file: &str,
45 out_file: &str,
46) -> Result<(), Box<dyn Error>> {
47 let template = liquid::ParserBuilder::with_liquid()
48 .build()?
49 .parse(&fs::read_to_string(in_file)?)?;
51 fs::write(out_file, template.render(variables)?)?;
52 Ok(())
55fn main() -> Result<(), Box<dyn Error>> {
56 let variables = init_template();
58 template(&variables, "assets/manual/bat.1.in", "assets/manual/bat.1")?;
59 template(
60 &variables,
61 "assets/completions/bat.fish.in",
62 "assets/completions/bat.fish",
63 )?;
65 Ok(())
68// #[macro_use]
69// extern crate clap;
71// use clap::Shell;
72// use std::fs;
74// include!("src/clap_app.rs");
76// const BIN_NAME: &str = "bat";
78// fn main() {
79// let outdir = std::env::var_os("SHELL_COMPLETIONS_DIR").or(std::env::var_os("OUT_DIR"));
81// let outdir = match outdir {
82// None => return,
83// Some(outdir) => outdir,
84// };
86// fs::create_dir_all(&outdir).unwrap();
88// let mut app = build_app(true);
89// app.gen_completions(BIN_NAME, Shell::Bash, &outdir);
90// app.gen_completions(BIN_NAME, Shell::Fish, &outdir);
91// app.gen_completions(BIN_NAME, Shell::Zsh, &outdir);
92// app.gen_completions(BIN_NAME, Shell::PowerShell, &outdir);
93// }