mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-02-05 03:58:25 +00:00
Display more information for non-release releases
This commit is contained in:
parent
e154b58268
commit
c7497f3778
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1,6 +1,6 @@
|
|||||||
[root]
|
[root]
|
||||||
name = "exa"
|
name = "exa"
|
||||||
version = "0.8.0"
|
version = "0.9.0-pre"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"datetime 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"datetime 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "exa"
|
name = "exa"
|
||||||
version = "0.8.0"
|
version = "0.9.0-pre"
|
||||||
authors = [ "ogham@bsago.me" ]
|
authors = [ "ogham@bsago.me" ]
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
description = "A modern replacement for ls"
|
description = "A modern replacement for ls"
|
||||||
homepage = "https://the.exa.website/"
|
homepage = "https://the.exa.website/"
|
||||||
@ -13,11 +14,13 @@ categories = ["command-line-utilities"]
|
|||||||
keywords = ["ls", "files", "command-line"]
|
keywords = ["ls", "files", "command-line"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "exa"
|
name = "exa"
|
||||||
path = "src/bin/main.rs"
|
path = "src/bin/main.rs"
|
||||||
doc = false
|
doc = false
|
||||||
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "exa"
|
name = "exa"
|
||||||
path = "src/exa.rs"
|
path = "src/exa.rs"
|
||||||
@ -41,6 +44,9 @@ unicode-width = "0.1.4"
|
|||||||
users = "0.5.2"
|
users = "0.5.2"
|
||||||
zoneinfo_compiled = "0.4.5"
|
zoneinfo_compiled = "0.4.5"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
datetime = "0.4.5"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "git" ]
|
default = [ "git" ]
|
||||||
git = [ "git2" ]
|
git = [ "git2" ]
|
||||||
|
59
build.rs
Normal file
59
build.rs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/// The version string isn’t the simplest: we want to show the version,
|
||||||
|
/// current Git hash, and compilation date when building *debug* versions, but
|
||||||
|
/// just the version for *release* versions so the builds are reproducible.
|
||||||
|
///
|
||||||
|
/// This script generates the string from the environment variables that Cargo
|
||||||
|
/// adds (http://doc.crates.io/environment-variables.html) and runs `git` to
|
||||||
|
/// get the SHA1 hash. It then writes the string into a file, which exa then
|
||||||
|
/// includes at build-time.
|
||||||
|
///
|
||||||
|
/// - https://stackoverflow.com/q/43753491/3484614
|
||||||
|
/// - https://crates.io/crates/vergen
|
||||||
|
|
||||||
|
extern crate datetime;
|
||||||
|
use std::io::Result as IOResult;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
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 main() {
|
||||||
|
write_statics().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_development_version() -> bool {
|
||||||
|
env::var("PROFILE").unwrap() == "debug"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cargo_version() -> String {
|
||||||
|
env::var("CARGO_PKG_VERSION").unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_date() -> String {
|
||||||
|
use datetime::{LocalDateTime, ISO};
|
||||||
|
|
||||||
|
let now = LocalDateTime::now();
|
||||||
|
format!("{}", now.date().iso())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_statics() -> IOResult<()> {
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
let ver = match is_development_version() {
|
||||||
|
true => format!("exa v{} ({} built on {})", cargo_version(), git_hash(), build_date()),
|
||||||
|
false => format!("exa v{}", cargo_version()),
|
||||||
|
};
|
||||||
|
|
||||||
|
let out = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
|
let mut f = File::create(&out.join("version_string.txt"))?;
|
||||||
|
write!(f, "{:?}", ver)
|
||||||
|
}
|
@ -1,16 +1,16 @@
|
|||||||
|
//! Printing the version string.
|
||||||
|
//!
|
||||||
|
//! The code that works out which string to print is done in `build.rs`.
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use options::flags;
|
use options::flags;
|
||||||
use options::parser::MatchedFlags;
|
use options::parser::MatchedFlags;
|
||||||
|
|
||||||
|
|
||||||
/// All the information needed to display the version information.
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub struct VersionString {
|
pub struct VersionString;
|
||||||
|
// There were options here once, but there aren’t anymore!
|
||||||
/// The version number from cargo.
|
|
||||||
cargo: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VersionString {
|
impl VersionString {
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ impl VersionString {
|
|||||||
/// Like --help, this doesn’t bother checking for errors.
|
/// Like --help, this doesn’t bother checking for errors.
|
||||||
pub fn deduce(matches: &MatchedFlags) -> Result<(), VersionString> {
|
pub fn deduce(matches: &MatchedFlags) -> Result<(), VersionString> {
|
||||||
if matches.count(&flags::VERSION) > 0 {
|
if matches.count(&flags::VERSION) > 0 {
|
||||||
Err(VersionString { cargo: env!("CARGO_PKG_VERSION") })
|
Err(VersionString)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Ok(()) // no version needs to be shown
|
Ok(()) // no version needs to be shown
|
||||||
@ -30,16 +30,12 @@ impl VersionString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for VersionString {
|
impl fmt::Display for VersionString {
|
||||||
|
|
||||||
/// Format this help options into an actual string of help
|
|
||||||
/// text to be displayed to the user.
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
write!(f, "exa v{}", self.cargo)
|
write!(f, "{}", include!(concat!(env!("OUT_DIR"), "/version_string.txt")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use options::Options;
|
use options::Options;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user