2019-01-26 16:29:21 +01:00
|
|
|
// TODO: Re-enable generation of shell completion files (below) when clap 3 is out.
|
|
|
|
// For more details, see https://github.com/sharkdp/bat/issues/372
|
2018-10-03 09:39:30 +02:00
|
|
|
|
2020-03-30 18:43:13 +02:00
|
|
|
// For bat-as-a-library, no build script is required. The build script is for
|
|
|
|
// the manpage and completions, which are only relevant to the bat application.
|
|
|
|
#[cfg(not(feature = "application"))]
|
|
|
|
fn main() {}
|
|
|
|
|
|
|
|
#[cfg(feature = "application")]
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
use std::error::Error;
|
|
|
|
use std::fs;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
// Read environment variables.
|
2020-04-24 16:16:36 +02:00
|
|
|
let project_name = option_env!("PROJECT_NAME").unwrap_or("bat");
|
|
|
|
let executable_name = option_env!("PROJECT_EXECUTABLE").unwrap_or(project_name);
|
|
|
|
static PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION");
|
2020-03-30 18:43:13 +02:00
|
|
|
|
|
|
|
/// Generates a file from a liquid template.
|
|
|
|
fn template(
|
|
|
|
variables: &liquid::Object,
|
|
|
|
in_file: &str,
|
|
|
|
out_file: impl AsRef<Path>,
|
|
|
|
) -> Result<(), Box<dyn Error>> {
|
|
|
|
let template = liquid::ParserBuilder::with_stdlib()
|
|
|
|
.build()?
|
|
|
|
.parse(&fs::read_to_string(in_file)?)?;
|
|
|
|
|
|
|
|
fs::write(out_file, template.render(variables)?)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-03-22 16:27:35 +01:00
|
|
|
let variables = liquid::object!({
|
2020-04-24 16:16:36 +02:00
|
|
|
"PROJECT_NAME": project_name,
|
|
|
|
"PROJECT_EXECUTABLE": executable_name,
|
|
|
|
"PROJECT_VERSION": PROJECT_VERSION,
|
2020-03-22 16:27:35 +01:00
|
|
|
});
|
2019-09-27 21:13:55 +02:00
|
|
|
|
2020-03-22 11:33:50 +01:00
|
|
|
let out_dir_env = std::env::var_os("OUT_DIR").expect("OUT_DIR to be set in build.rs");
|
|
|
|
let out_dir = Path::new(&out_dir_env);
|
|
|
|
|
2020-04-24 07:56:54 +02:00
|
|
|
fs::create_dir_all(out_dir.join("assets/manual")).unwrap();
|
|
|
|
fs::create_dir_all(out_dir.join("assets/completions")).unwrap();
|
2020-03-22 11:33:50 +01:00
|
|
|
|
|
|
|
template(
|
|
|
|
&variables,
|
|
|
|
"assets/manual/bat.1.in",
|
|
|
|
out_dir.join("assets/manual/bat.1"),
|
|
|
|
)?;
|
2019-09-27 21:13:55 +02:00
|
|
|
template(
|
|
|
|
&variables,
|
|
|
|
"assets/completions/bat.fish.in",
|
2020-03-22 11:33:50 +01:00
|
|
|
out_dir.join("assets/completions/bat.fish"),
|
2019-09-27 21:13:55 +02:00
|
|
|
)?;
|
|
|
|
|
2019-09-27 21:06:54 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
2018-10-03 09:39:30 +02:00
|
|
|
|
2019-01-26 16:29:21 +01:00
|
|
|
// #[macro_use]
|
|
|
|
// extern crate clap;
|
2018-10-03 09:39:30 +02:00
|
|
|
|
2019-01-26 16:29:21 +01:00
|
|
|
// use clap::Shell;
|
|
|
|
// use std::fs;
|
2018-10-03 09:39:30 +02:00
|
|
|
|
2019-01-26 16:29:21 +01:00
|
|
|
// include!("src/clap_app.rs");
|
2018-10-03 09:39:30 +02:00
|
|
|
|
2019-01-26 16:29:21 +01:00
|
|
|
// const BIN_NAME: &str = "bat";
|
2018-10-03 09:39:30 +02:00
|
|
|
|
2019-01-26 16:29:21 +01:00
|
|
|
// fn main() {
|
|
|
|
// let outdir = std::env::var_os("SHELL_COMPLETIONS_DIR").or(std::env::var_os("OUT_DIR"));
|
2018-10-03 09:39:30 +02:00
|
|
|
|
2019-01-26 16:29:21 +01:00
|
|
|
// let outdir = match outdir {
|
|
|
|
// None => return,
|
|
|
|
// Some(outdir) => outdir,
|
|
|
|
// };
|
|
|
|
|
|
|
|
// fs::create_dir_all(&outdir).unwrap();
|
|
|
|
|
|
|
|
// let mut app = build_app(true);
|
|
|
|
// app.gen_completions(BIN_NAME, Shell::Bash, &outdir);
|
|
|
|
// app.gen_completions(BIN_NAME, Shell::Fish, &outdir);
|
|
|
|
// app.gen_completions(BIN_NAME, Shell::Zsh, &outdir);
|
|
|
|
// app.gen_completions(BIN_NAME, Shell::PowerShell, &outdir);
|
|
|
|
// }
|