aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-02-14 16:21:39 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-02-14 16:21:39 +0100
commit431538e9c90090c8802460f3a625a0cd38a5e72a (patch)
tree16c5683083409b8d6ec2e1d0e8e8140f4a39e524
parentbuild(scripts/cprh): Remove (diff)
downloadyt-431538e9c90090c8802460f3a625a0cd38a5e72a.zip
feat(version): Include `yt-dlp` and `python` version in `--version`
Both are run-time dependencies and need to be up-to-date (especially, `yt-dlp`)
Diffstat (limited to '')
-rw-r--r--yt/src/cli.rs6
-rw-r--r--yt/src/main.rs6
-rw-r--r--yt/src/version/mod.rs32
3 files changed, 43 insertions, 1 deletions
diff --git a/yt/src/cli.rs b/yt/src/cli.rs
index d7e084a..5e7af5b 100644
--- a/yt/src/cli.rs
+++ b/yt/src/cli.rs
@@ -22,7 +22,7 @@ use crate::{
};
#[derive(Parser, Debug)]
-#[clap(author, version, about, long_about = None)]
+#[clap(author, about, long_about = None)]
#[allow(clippy::module_name_repetitions)]
/// An command line interface to select, download and watch videos
pub struct CliArgs {
@@ -30,6 +30,10 @@ pub struct CliArgs {
/// The subcommand to execute [default: select]
pub command: Option<Command>,
+ /// Show the version and exit
+ #[arg(long, short = 'V', action= ArgAction::SetTrue)]
+ pub version: bool,
+
/// Increase message verbosity
#[arg(long="verbose", short = 'v', action = ArgAction::Count)]
pub verbosity: u8,
diff --git a/yt/src/main.rs b/yt/src/main.rs
index fbfdac0..3097eea 100644
--- a/yt/src/main.rs
+++ b/yt/src/main.rs
@@ -50,6 +50,7 @@ pub mod status;
pub mod storage;
pub mod subscribe;
pub mod update;
+pub mod version;
pub mod videos;
pub mod watch;
@@ -59,6 +60,11 @@ pub mod watch;
async fn main() -> Result<()> {
let args = cli::CliArgs::parse();
+ if args.version {
+ version::show()?;
+ return Ok(());
+ }
+
// The default verbosity is 1 (Warn)
let verbosity: u8 = args.verbosity + 1;
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(())
+}