mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Add (short) commit hash and build time to version hash
This commit is contained in:
parent
59b5e3d239
commit
b1182d4f7b
4 changed files with 62 additions and 13 deletions
7
build.rs
7
build.rs
|
|
@ -2,14 +2,7 @@ use clap::{Command, CommandFactory};
|
|||
use clap_complete::shells;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
// this build file generates completions for various shells as well as manual pages
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
// do not generate anything when building non release
|
||||
if cfg!(debug_assertions) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// note that we're using an anti-pattern here / violate the rust conventions. build script are
|
||||
// not supposed to write outside of 'OUT_DIR'. to have the generated files in the build "root"
|
||||
// (the same directory where the output binary lives) is much simpler than in 'OUT_DIR' since
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ static-ssl = ["crunchyroll-rs/static-ssl"]
|
|||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
async-trait = "0.1"
|
||||
clap = { version = "4.0", features = ["derive"] }
|
||||
clap = { version = "4.0", features = ["derive", "string"] }
|
||||
chrono = "0.4"
|
||||
crunchyroll-rs = { git = "https://github.com/crunchy-labs/crunchyroll-rs", default-features = false, features = ["stream", "parse"] }
|
||||
ctrlc = "3.2"
|
||||
|
|
@ -28,3 +28,6 @@ tempfile = "3.3"
|
|||
terminal_size = "0.2"
|
||||
tokio = { version = "1.21", features = ["macros", "rt-multi-thread", "time"] }
|
||||
sys-locale = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
chrono = "0.4"
|
||||
|
|
|
|||
33
crunchy-cli-core/build.rs
Normal file
33
crunchy-cli-core/build.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
fn main() -> std::io::Result<()> {
|
||||
println!(
|
||||
"cargo:rustc-env=GIT_HASH={}",
|
||||
get_short_commit_hash()?.unwrap_or_default()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=BUILD_DATE={}",
|
||||
chrono::Utc::now().format("%F")
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_short_commit_hash() -> std::io::Result<Option<String>> {
|
||||
let git = std::process::Command::new("git")
|
||||
.arg("rev-parse")
|
||||
.arg("--short")
|
||||
.arg("HEAD")
|
||||
.output();
|
||||
|
||||
match git {
|
||||
Ok(cmd) => Ok(Some(
|
||||
String::from_utf8_lossy(cmd.stdout.as_slice()).to_string(),
|
||||
)),
|
||||
Err(e) => {
|
||||
if e.kind() != std::io::ErrorKind::NotFound {
|
||||
Err(e)
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,13 +20,15 @@ trait Execute {
|
|||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(author, version, about)]
|
||||
#[clap(author, version = version(), about)]
|
||||
#[clap(name = "crunchy-cli")]
|
||||
pub struct Cli {
|
||||
#[clap(flatten)]
|
||||
verbosity: Option<Verbosity>,
|
||||
|
||||
#[arg(help = "Overwrite the language in which results are returned. Default is your system language")]
|
||||
#[arg(
|
||||
help = "Overwrite the language in which results are returned. Default is your system language"
|
||||
)]
|
||||
#[arg(long)]
|
||||
lang: Option<Locale>,
|
||||
|
||||
|
|
@ -37,6 +39,18 @@ pub struct Cli {
|
|||
command: Command,
|
||||
}
|
||||
|
||||
fn version() -> String {
|
||||
let package_version = env!("CARGO_PKG_VERSION");
|
||||
let git_commit_hash = env!("GIT_HASH");
|
||||
let build_date = env!("BUILD_DATE");
|
||||
|
||||
if git_commit_hash.is_empty() {
|
||||
format!("{}", package_version)
|
||||
} else {
|
||||
format!("{} ({} {})", package_version, git_commit_hash, build_date)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum Command {
|
||||
Archive(Archive),
|
||||
|
|
@ -51,7 +65,9 @@ struct Verbosity {
|
|||
v: bool,
|
||||
|
||||
#[arg(help = "Quiet output. Does not print anything unless it's a error")]
|
||||
#[arg(long_help = "Quiet output. Does not print anything unless it's a error. Can be helpful if you pipe the output to stdout")]
|
||||
#[arg(
|
||||
long_help = "Quiet output. Does not print anything unless it's a error. Can be helpful if you pipe the output to stdout"
|
||||
)]
|
||||
#[arg(short)]
|
||||
q: bool,
|
||||
}
|
||||
|
|
@ -59,11 +75,15 @@ struct Verbosity {
|
|||
#[derive(Debug, Parser)]
|
||||
struct LoginMethod {
|
||||
#[arg(help = "Login with credentials (username or email and password)")]
|
||||
#[arg(long_help = "Login with credentials (username or email and password). Must be provided as user:password")]
|
||||
#[arg(
|
||||
long_help = "Login with credentials (username or email and password). Must be provided as user:password"
|
||||
)]
|
||||
#[arg(long)]
|
||||
credentials: Option<String>,
|
||||
#[arg(help = "Login with the etp-rt cookie")]
|
||||
#[arg(long_help = "Login with the etp-rt cookie. This can be obtained when you login on crunchyroll.com and extract it from there")]
|
||||
#[arg(
|
||||
long_help = "Login with the etp-rt cookie. This can be obtained when you login on crunchyroll.com and extract it from there"
|
||||
)]
|
||||
#[arg(long)]
|
||||
etp_rt: Option<String>,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue