mirror of
https://github.com/apognu/tuigreet.git
synced 2024-08-17 02:20:51 +03:00
Added --version.
This commit is contained in:
parent
35e5445060
commit
e74d8c2b1d
@ -3,6 +3,7 @@ name = "tuigreet"
|
||||
version = "0.1.0"
|
||||
authors = ["Antoine POPINEAU <antoine.popineau@appscho.com>"]
|
||||
edition = "2018"
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "0.2.21"
|
||||
|
@ -9,6 +9,7 @@ Usage: tuigreet [OPTIONS]
|
||||
|
||||
Options:
|
||||
-h, --help show this usage information
|
||||
-v, --version print version information
|
||||
-c, --cmd COMMAND command to run
|
||||
-w, --width WIDTH width of the main prompt (default: 80)
|
||||
-i, --issue show the host's issue file
|
||||
|
24
build.rs
Normal file
24
build.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use std::{env, error::Error, process::Command};
|
||||
|
||||
fn main() {
|
||||
let version = get_version().unwrap_or_else(|_| String::from("unknown"));
|
||||
|
||||
println!("cargo:rustc-env=VERSION={}", version);
|
||||
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
|
||||
}
|
||||
|
||||
fn get_version() -> Result<String, Box<dyn Error>> {
|
||||
let tag = Command::new("git").args(&["describe", "--tags", "--abbrev=0"]).output()?;
|
||||
let tag = match tag.status.code() {
|
||||
Some(0) => String::from_utf8(tag.stdout)?,
|
||||
_ => "0.0.0".to_string(),
|
||||
};
|
||||
let count = String::from_utf8(Command::new("git").args(&["rev-list", "--count", "HEAD"]).output()?.stdout)?;
|
||||
let commit = String::from_utf8(Command::new("git").args(&["rev-parse", "--short", "HEAD"]).output()?.stdout)?;
|
||||
let version = format!("{}.r{}.{}", tag.trim(), count.trim(), commit.trim());
|
||||
|
||||
match version.as_str() {
|
||||
"0.0.0.r." => Err("could not retrieve version".into()),
|
||||
version => Ok(version.to_string()),
|
||||
}
|
||||
}
|
@ -124,6 +124,7 @@ impl Greeter {
|
||||
let mut opts = Options::new();
|
||||
|
||||
opts.optflag("h", "help", "show this usage information");
|
||||
opts.optflag("v", "version", "print version information");
|
||||
opts.optopt("c", "cmd", "command to run", "COMMAND");
|
||||
opts.optopt("w", "width", "width of the main prompt (default: 80)", "WIDTH");
|
||||
opts.optflag("i", "issue", "show the host's issue file");
|
||||
@ -146,6 +147,10 @@ impl Greeter {
|
||||
print_usage(opts);
|
||||
std::process::exit(0);
|
||||
}
|
||||
if self.config().opt_present("version") {
|
||||
print_version();
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
let socket = env::var("GREETD_SOCK");
|
||||
if socket.is_err() {
|
||||
@ -180,3 +185,9 @@ impl Greeter {
|
||||
fn print_usage(opts: Options) {
|
||||
eprint!("{}", opts.usage("Usage: tuigreet [OPTIONS]"));
|
||||
}
|
||||
|
||||
fn print_version() {
|
||||
println!("tuigreet {} ({})", env!("VERSION"), env!("TARGET"));
|
||||
println!("Copyright (C) 2020 Antoine POPINEAU <https://github.com/apognu/tuigreet>.");
|
||||
println!("Licensed under GPLv3 (GNU GPL version 3 or later).");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user