about summary refs log tree commit diff stats
path: root/crates/yt/src/version/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/yt/src/version/mod.rs')
-rw-r--r--crates/yt/src/version/mod.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/crates/yt/src/version/mod.rs b/crates/yt/src/version/mod.rs
new file mode 100644
index 0000000..2cc41c7
--- /dev/null
+++ b/crates/yt/src/version/mod.rs
@@ -0,0 +1,52 @@
+// yt - A fully featured command line YouTube client
+//
+// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// This file is part of Yt.
+//
+// You should have received a copy of the License along with this program.
+// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+use anyhow::{Context, Result};
+use sqlx::{SqlitePool, sqlite::SqliteConnectOptions};
+use yt_dlp::options::YoutubeDLOptions;
+
+use crate::{config::Config, storage::migrate::get_version_db};
+
+pub async fn show(config: &Config) -> Result<()> {
+    let db_version = {
+        let options = SqliteConnectOptions::new()
+            .filename(&config.paths.database_path)
+            .optimize_on_close(true, None)
+            .create_if_missing(true);
+
+        let pool = SqlitePool::connect_with(options)
+            .await
+            .context("Failed to connect to database!")?;
+
+        get_version_db(&pool)
+            .await
+            .context("Failed to determine database version")?
+    };
+
+    let (yt_dlp, python) = {
+        let yt_dlp = YoutubeDLOptions::new().build()?;
+        yt_dlp.version()
+    };
+
+    let python = python.replace('\n', " ");
+
+    println!(
+        "{}: {}
+
+db version: {db_version}
+
+yt-dlp: {yt_dlp}
+python: {python}",
+        env!("CARGO_PKG_NAME"),
+        env!("CARGO_PKG_VERSION"),
+    );
+
+    Ok(())
+}