12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- use std::env;
- use std::fs::File;
- use std::io::{self, Write};
- use std::path::PathBuf;
- use datetime::{LocalDateTime, ISO};
- use regex::Regex;
- fn main() -> io::Result<()> {
- #![allow(clippy::write_with_newline)]
- let usage = include_str!("src/usage.txt");
- let tagline = "dog \\1;32m●\\0m command-line DNS client";
- let url = "https://dns.lookup.dog/";
- let ver = if is_development_version() {
- format!("{}\nv{} [{}] built on {} \\1;31m(pre-release!)\\0m\n\\1;4;34m{}\\0m", tagline, cargo_version(), git_hash(), build_date(), url)
- }
- else {
- format!("{}\nv{}\n\\1;4;34m{}\\0m", tagline, cargo_version(), url)
- };
-
- let out = PathBuf::from(env::var("OUT_DIR").unwrap());
-
- let control_code = Regex::new(r##"\\.+?m"##).unwrap();
-
- let mut f = File::create(&out.join("version.pretty.txt"))?;
- write!(f, "{}\n", ver.replace("\\", "\x1B["))?;
-
- let mut f = File::create(&out.join("version.bland.txt"))?;
- write!(f, "{}\n", control_code.replace_all(&ver, ""))?;
-
- let mut f = File::create(&out.join("usage.pretty.txt"))?;
- write!(f, "{}\n\n{}", tagline.replace("\\", "\x1B["), usage.replace("\\", "\x1B["))?;
-
- let mut f = File::create(&out.join("usage.bland.txt"))?;
- write!(f, "{}\n\n{}", control_code.replace_all(tagline, ""), control_code.replace_all(usage, ""))?;
- Ok(())
- }
- fn git_hash() -> String {
- use std::process::Command;
- String::from_utf8_lossy(
- &Command::new("git")
- .args(&["rev-parse", "--short", "HEAD"])
- .output().unwrap()
- .stdout).trim().to_string()
- }
- fn is_development_version() -> bool {
- cargo_version().ends_with("-pre") || env::var("PROFILE").unwrap() == "debug"
- }
- fn cargo_version() -> String {
- env::var("CARGO_PKG_VERSION").unwrap()
- }
- fn build_date() -> String {
- let now = LocalDateTime::now();
- format!("{}", now.date().iso())
- }
|