aboutsummaryrefslogtreecommitdiffstats
path: root/yt/src/version/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'yt/src/version/mod.rs')
-rw-r--r--yt/src/version/mod.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/yt/src/version/mod.rs b/yt/src/version/mod.rs
new file mode 100644
index 0000000..369541e
--- /dev/null
+++ b/yt/src/version/mod.rs
@@ -0,0 +1,32 @@
+use std::process::Command;
+
+use anyhow::{Context, Result};
+
+fn get_cmd_version(cmd: &str) -> Result<String> {
+ let out = String::from_utf8(
+ Command::new(cmd)
+ .arg("--version")
+ .output()
+ .with_context(|| format!("Failed to run `{cmd} --version`"))?
+ .stdout,
+ )
+ .context("Failed to interpret output as utf8")?;
+
+ Ok(out.trim().to_owned())
+}
+
+pub fn show() -> Result<()> {
+ let python_version = get_cmd_version("python")?;
+ let yt_dlp_version = get_cmd_version("yt-dlp")?;
+
+ println!(
+ "{}: {}
+
+python: {python_version}
+yt-dlp: {yt_dlp_version}",
+ env!("CARGO_PKG_NAME"),
+ env!("CARGO_PKG_VERSION"),
+ );
+
+ Ok(())
+}