about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-24 16:42:56 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-24 16:42:56 +0200
commited9956b784b087f1610f472954339990f79eec49 (patch)
treed8a532ad9d52a1c951f1b4583747741482809d43
parentfix(crates/yt): Correct imports (diff)
downloadyt-ed9956b784b087f1610f472954339990f79eec49.zip
refactor(crates/yt/commands): Restrict visibility to itself
This ensures, that the other code in `yt` does not reference this.
-rw-r--r--crates/yt/src/commands/config/implm.rs2
-rw-r--r--crates/yt/src/commands/config/mod.rs2
-rw-r--r--crates/yt/src/commands/database/implm.rs2
-rw-r--r--crates/yt/src/commands/download/implm/mod.rs2
-rw-r--r--crates/yt/src/commands/download/mod.rs2
-rw-r--r--crates/yt/src/commands/implm.rs4
-rw-r--r--crates/yt/src/commands/mod.rs5
-rw-r--r--crates/yt/src/commands/playlist/implm.rs2
-rw-r--r--crates/yt/src/commands/playlist/mod.rs2
-rw-r--r--crates/yt/src/commands/select/implm/mod.rs16
-rw-r--r--crates/yt/src/commands/select/mod.rs37
-rw-r--r--crates/yt/src/commands/show/implm/mod.rs2
-rw-r--r--crates/yt/src/commands/status/implm.rs2
-rw-r--r--crates/yt/src/commands/status/mod.rs2
-rw-r--r--crates/yt/src/commands/subscriptions/implm.rs2
-rw-r--r--crates/yt/src/commands/subscriptions/mod.rs2
-rw-r--r--crates/yt/src/commands/update/implm/mod.rs4
-rw-r--r--crates/yt/src/commands/update/mod.rs2
-rw-r--r--crates/yt/src/commands/videos/implm.rs2
-rw-r--r--crates/yt/src/commands/videos/mod.rs2
-rw-r--r--crates/yt/src/commands/watch/implm/mod.rs2
-rw-r--r--crates/yt/src/commands/watch/mod.rs2
22 files changed, 52 insertions, 48 deletions
diff --git a/crates/yt/src/commands/config/implm.rs b/crates/yt/src/commands/config/implm.rs
index 409ef43..47b7fee 100644
--- a/crates/yt/src/commands/config/implm.rs
+++ b/crates/yt/src/commands/config/implm.rs
@@ -3,7 +3,7 @@ use crate::{app::App, commands::config::ConfigCommand};
 use anyhow::Result;
 
 impl ConfigCommand {
-    pub(crate) fn implm(self, app: &App) -> Result<()> {
+    pub(in crate::commands) fn implm(self, app: &App) -> Result<()> {
         let config_str = toml::to_string(&app.config)?;
 
         print!("{config_str}");
diff --git a/crates/yt/src/commands/config/mod.rs b/crates/yt/src/commands/config/mod.rs
index 9ec289b..ff97aab 100644
--- a/crates/yt/src/commands/config/mod.rs
+++ b/crates/yt/src/commands/config/mod.rs
@@ -3,4 +3,4 @@ use clap::Parser;
 mod implm;
 
 #[derive(Parser, Debug)]
-pub(crate) struct ConfigCommand {}
+pub(super) struct ConfigCommand {}
diff --git a/crates/yt/src/commands/database/implm.rs b/crates/yt/src/commands/database/implm.rs
index 0caaeb2..8d81f2e 100644
--- a/crates/yt/src/commands/database/implm.rs
+++ b/crates/yt/src/commands/database/implm.rs
@@ -10,7 +10,7 @@ use crate::{
 use anyhow::Result;
 
 impl DatabaseCommand {
-    pub(crate) async fn implm(&self, app: &App) -> Result<()> {
+    pub(in crate::commands) async fn implm(&self, app: &App) -> Result<()> {
         match self {
             DatabaseCommand::Log { kind } => match kind {
                 super::OperationType::Video => {
diff --git a/crates/yt/src/commands/download/implm/mod.rs b/crates/yt/src/commands/download/implm/mod.rs
index e8867cf..f681aea 100644
--- a/crates/yt/src/commands/download/implm/mod.rs
+++ b/crates/yt/src/commands/download/implm/mod.rs
@@ -16,7 +16,7 @@ use log::info;
 mod download;
 
 impl DownloadCommand {
-    pub(crate) async fn implm(self, app: Arc<App>) -> Result<()> {
+    pub(in crate::commands) async fn implm(self, app: Arc<App>) -> Result<()> {
         let DownloadCommand {
             force,
             max_cache_size,
diff --git a/crates/yt/src/commands/download/mod.rs b/crates/yt/src/commands/download/mod.rs
index 48c6ee4..432865f 100644
--- a/crates/yt/src/commands/download/mod.rs
+++ b/crates/yt/src/commands/download/mod.rs
@@ -6,7 +6,7 @@ use crate::shared::bytes::Bytes;
 mod implm;
 
 #[derive(Parser, Debug)]
-pub(crate) struct DownloadCommand {
+pub(super) struct DownloadCommand {
     /// Forcefully re-download all cached videos (i.e. delete all already downloaded paths, then download).
     #[arg(short, long)]
     force: bool,
diff --git a/crates/yt/src/commands/implm.rs b/crates/yt/src/commands/implm.rs
index 238ef28..119b721 100644
--- a/crates/yt/src/commands/implm.rs
+++ b/crates/yt/src/commands/implm.rs
@@ -11,7 +11,9 @@ impl Command {
             Command::Database { cmd } => cmd.implm(&app).await?,
             Command::Download { cmd } => cmd.implm(Arc::new(app)).await?,
             Command::Playlist { cmd } => cmd.implm(&app).await?,
-            Command::Select { cmd } => { cmd.unwrap_or_default().implm(&app).await?; }
+            Command::Select { cmd } => {
+                cmd.unwrap_or_default().implm(&app).await?;
+            }
             Command::Show { cmd } => cmd.implm(&app).await?,
             Command::Status { cmd } => cmd.implm(&app).await?,
             Command::Subscriptions { cmd } => cmd.implm(&app).await?,
diff --git a/crates/yt/src/commands/mod.rs b/crates/yt/src/commands/mod.rs
index ee8b29c..7984f1c 100644
--- a/crates/yt/src/commands/mod.rs
+++ b/crates/yt/src/commands/mod.rs
@@ -16,7 +16,7 @@ use crate::{
     storage::db::subscription::Subscriptions,
 };
 
-pub(crate) mod implm;
+pub(super) mod implm;
 
 mod config;
 mod database;
@@ -31,7 +31,8 @@ mod videos;
 mod watch;
 
 #[derive(Subcommand, Debug)]
-pub(crate) enum Command {
+#[allow(private_interfaces)] // Only the main `implm` method should be accessible.
+pub(super) enum Command {
     /// Show, the configuration options in effect.
     Config {
         #[command(flatten)]
diff --git a/crates/yt/src/commands/playlist/implm.rs b/crates/yt/src/commands/playlist/implm.rs
index ce4b394..52a0977 100644
--- a/crates/yt/src/commands/playlist/implm.rs
+++ b/crates/yt/src/commands/playlist/implm.rs
@@ -18,7 +18,7 @@ use anyhow::Result;
 use futures::{TryStreamExt, stream::FuturesOrdered};
 
 impl PlaylistCommand {
-    pub(crate) async fn implm(self, app: &App) -> Result<()> {
+    pub(in crate::commands) async fn implm(self, app: &App) -> Result<()> {
         let PlaylistCommand { watch } = self;
 
         let mut previous_output_length = 0;
diff --git a/crates/yt/src/commands/playlist/mod.rs b/crates/yt/src/commands/playlist/mod.rs
index 8290b3e..6f7b255 100644
--- a/crates/yt/src/commands/playlist/mod.rs
+++ b/crates/yt/src/commands/playlist/mod.rs
@@ -3,7 +3,7 @@ use clap::Parser;
 mod implm;
 
 #[derive(Parser, Debug)]
-pub(crate) struct PlaylistCommand {
+pub(super) struct PlaylistCommand {
     /// Linger and display changes
     #[arg(short, long)]
     watch: bool,
diff --git a/crates/yt/src/commands/select/implm/mod.rs b/crates/yt/src/commands/select/implm/mod.rs
index 755076c..155012c 100644
--- a/crates/yt/src/commands/select/implm/mod.rs
+++ b/crates/yt/src/commands/select/implm/mod.rs
@@ -6,34 +6,34 @@ mod fs_generators;
 mod standalone;
 
 impl SelectCommand {
-    pub(crate) async fn implm(self, app: &App) -> Result<()> {
+    pub(in crate::commands) async fn implm(self, app: &App) -> Result<()> {
         match self {
             SelectCommand::File {
                 done,
                 use_last_selection,
-            } => Box::pin(fs_generators::select_file(&app, done, use_last_selection)).await?,
+            } => Box::pin(fs_generators::select_file(app, done, use_last_selection)).await?,
             SelectCommand::Split {
                 done,
                 sort_key,
                 sort_mode,
-            } => Box::pin(fs_generators::select_split(&app, done, sort_key, sort_mode)).await?,
+            } => Box::pin(fs_generators::select_split(app, done, sort_key, sort_mode)).await?,
             SelectCommand::Add { urls, start, stop } => {
-                Box::pin(standalone::add::add(&app, urls, start, stop)).await?;
+                Box::pin(standalone::add::add(app, urls, start, stop)).await?;
             }
             other => {
                 let shared = other
                     .clone()
                     .into_shared()
                     .expect("The ones without shared should have been filtered out.");
-                let hash = shared.hash.realize(&app, None).await?;
+                let hash = shared.hash.realize(app, None).await?;
                 let mut video = hash
-                    .get_with_app(&app)
+                    .get_with_app(app)
                     .await
                     .expect("The hash was already realized, it should therefore exist");
 
                 let mut ops = Operations::new("Main: handle select cmd");
-                standalone::handle_select_cmd(&app, other, &mut video, None, &mut ops).await?;
-                ops.commit(&app).await?;
+                standalone::handle_select_cmd(app, other, &mut video, None, &mut ops).await?;
+                ops.commit(app).await?;
             }
         }
 
diff --git a/crates/yt/src/commands/select/mod.rs b/crates/yt/src/commands/select/mod.rs
index f9a8cd4..3ab2972 100644
--- a/crates/yt/src/commands/select/mod.rs
+++ b/crates/yt/src/commands/select/mod.rs
@@ -14,7 +14,8 @@ mod implm;
 #[derive(Subcommand, Clone, Debug)]
 // NOTE: Keep this in sync with the [`constants::HELP_STR`] constant. <2024-08-20>
 // NOTE: Also keep this in sync with the `tree-sitter-yts/grammar.js`. <2024-11-04>
-pub(crate) enum SelectCommand {
+#[allow(private_interfaces)] // Only the main `implm` method should be accessible.
+pub(super) enum SelectCommand {
     /// Open a `git rebase` like file to select the videos to watch (the default)
     File {
         /// Include done (watched, dropped) videos
@@ -106,35 +107,35 @@ impl Default for SelectCommand {
 #[derive(Clone, Debug, Args)]
 #[command(infer_subcommands = true)]
 /// Mark the video given by the hash to be watched
-pub(crate) struct SharedSelectionCommandArgs {
+struct SharedSelectionCommandArgs {
     /// The ordering priority (higher means more at the top)
     #[arg(short, long)]
-    pub(crate) priority: Option<i64>,
+    priority: Option<i64>,
 
     /// The subtitles to download (e.g. 'en,de,sv')
     #[arg(short = 'l', long)]
-    pub(crate) subtitle_langs: Option<String>,
+    subtitle_langs: Option<String>,
 
     /// The speed to set mpv to
     #[arg(short = 's', long)]
-    pub(crate) playback_speed: Option<f64>,
+    playback_speed: Option<f64>,
 
     /// The short extractor hash
-    pub(crate) hash: LazyExtractorHash,
+    hash: LazyExtractorHash,
 
-    pub(crate) title: Option<String>,
+    title: Option<String>,
 
-    pub(crate) date: Option<OptionalNaiveDate>,
+    date: Option<OptionalNaiveDate>,
 
-    pub(crate) publisher: Option<OptionalPublisher>,
+    publisher: Option<OptionalPublisher>,
 
-    pub(crate) duration: Option<MaybeDuration>,
+    duration: Option<MaybeDuration>,
 
-    pub(crate) url: Option<Url>,
+    url: Option<Url>,
 }
 
 impl SelectCommand {
-    pub(crate) fn into_shared(self) -> Option<SharedSelectionCommandArgs> {
+    fn into_shared(self) -> Option<SharedSelectionCommandArgs> {
         match self {
             SelectCommand::File { .. }
             | SelectCommand::Split { .. }
@@ -149,8 +150,8 @@ impl SelectCommand {
 }
 
 #[derive(Clone, Debug, Copy)]
-pub(crate) struct OptionalNaiveDate {
-    pub(crate) date: Option<NaiveDate>,
+struct OptionalNaiveDate {
+    date: Option<NaiveDate>,
 }
 impl FromStr for OptionalNaiveDate {
     type Err = anyhow::Error;
@@ -165,8 +166,8 @@ impl FromStr for OptionalNaiveDate {
     }
 }
 #[derive(Clone, Debug)]
-pub(crate) struct OptionalPublisher {
-    pub(crate) publisher: Option<String>,
+struct OptionalPublisher {
+    publisher: Option<String>,
 }
 impl FromStr for OptionalPublisher {
     type Err = anyhow::Error;
@@ -182,7 +183,7 @@ impl FromStr for OptionalPublisher {
 }
 
 #[derive(Default, ValueEnum, Clone, Copy, Debug)]
-pub(crate) enum SelectSplitSortKey {
+enum SelectSplitSortKey {
     /// Sort by the name of the publisher.
     #[default]
     Publisher,
@@ -200,7 +201,7 @@ impl Display for SelectSplitSortKey {
 }
 
 #[derive(Default, ValueEnum, Clone, Copy, Debug)]
-pub(crate) enum SelectSplitSortMode {
+enum SelectSplitSortMode {
     /// Sort in ascending order (small -> big)
     #[default]
     Asc,
diff --git a/crates/yt/src/commands/show/implm/mod.rs b/crates/yt/src/commands/show/implm/mod.rs
index 158a25b..66f9fa7 100644
--- a/crates/yt/src/commands/show/implm/mod.rs
+++ b/crates/yt/src/commands/show/implm/mod.rs
@@ -16,7 +16,7 @@ use tempfile::Builder;
 use tokio_util::bytes::Buf;
 
 impl ShowCommand {
-    pub(crate) async fn implm(&self, app: &App) -> Result<()> {
+    pub(in crate::commands) async fn implm(&self, app: &App) -> Result<()> {
         match self {
             ShowCommand::Description {} => {
                 let description = Video::get_current_description(app).await?;
diff --git a/crates/yt/src/commands/status/implm.rs b/crates/yt/src/commands/status/implm.rs
index fc046c9..bdce6ee 100644
--- a/crates/yt/src/commands/status/implm.rs
+++ b/crates/yt/src/commands/status/implm.rs
@@ -31,7 +31,7 @@ macro_rules! get {
 }
 
 impl StatusCommand {
-    pub(crate) async fn implm(self, app: &App) -> Result<()> {
+    pub(in crate::commands) async fn implm(self, app: &App) -> Result<()> {
         let StatusCommand { format } = self;
 
         let all_videos = Video::in_states(app, VideoStatusMarker::ALL).await?;
diff --git a/crates/yt/src/commands/status/mod.rs b/crates/yt/src/commands/status/mod.rs
index dc6e865..d333fb4 100644
--- a/crates/yt/src/commands/status/mod.rs
+++ b/crates/yt/src/commands/status/mod.rs
@@ -3,7 +3,7 @@ use clap::Parser;
 mod implm;
 
 #[derive(Parser, Debug)]
-pub(crate) struct StatusCommand {
+pub(super) struct StatusCommand {
     /// Which format to use
     #[arg(short, long)]
     format: Option<String>,
diff --git a/crates/yt/src/commands/subscriptions/implm.rs b/crates/yt/src/commands/subscriptions/implm.rs
index 311ae2b..6001c85 100644
--- a/crates/yt/src/commands/subscriptions/implm.rs
+++ b/crates/yt/src/commands/subscriptions/implm.rs
@@ -19,7 +19,7 @@ use url::Url;
 use yt_dlp::{json_cast, json_get, json_try_get, options::YoutubeDLOptions};
 
 impl SubscriptionCommand {
-    pub(crate) async fn implm(self, app: &App) -> Result<()> {
+    pub(in crate::commands) async fn implm(self, app: &App) -> Result<()> {
         match self {
             SubscriptionCommand::Add {
                 name,
diff --git a/crates/yt/src/commands/subscriptions/mod.rs b/crates/yt/src/commands/subscriptions/mod.rs
index 530f5f5..57d065b 100644
--- a/crates/yt/src/commands/subscriptions/mod.rs
+++ b/crates/yt/src/commands/subscriptions/mod.rs
@@ -9,7 +9,7 @@ use crate::commands::complete_subscription;
 mod implm;
 
 #[derive(Subcommand, Clone, Debug)]
-pub(crate) enum SubscriptionCommand {
+pub(super) enum SubscriptionCommand {
     /// Subscribe to an URL
     Add {
         #[arg(short, long)]
diff --git a/crates/yt/src/commands/update/implm/mod.rs b/crates/yt/src/commands/update/implm/mod.rs
index bb9323e..0bb6d99 100644
--- a/crates/yt/src/commands/update/implm/mod.rs
+++ b/crates/yt/src/commands/update/implm/mod.rs
@@ -12,13 +12,13 @@ use anyhow::{Result, bail};
 mod updater;
 
 impl UpdateCommand {
-    pub(crate) async fn implm(self, app: &App) -> Result<()> {
+    pub(in crate::commands) async fn implm(self, app: &App) -> Result<()> {
         let UpdateCommand {
             max_backlog,
             subscriptions: subscription_names_to_update,
         } = self;
 
-        let mut all_subs = Subscriptions::get(&app).await?;
+        let mut all_subs = Subscriptions::get(app).await?;
 
         let max_backlog = max_backlog.unwrap_or(app.config.update.max_backlog);
 
diff --git a/crates/yt/src/commands/update/mod.rs b/crates/yt/src/commands/update/mod.rs
index 6f1c865..6c605b4 100644
--- a/crates/yt/src/commands/update/mod.rs
+++ b/crates/yt/src/commands/update/mod.rs
@@ -6,7 +6,7 @@ use crate::commands::complete_subscription;
 mod implm;
 
 #[derive(Parser, Debug)]
-pub(crate) struct UpdateCommand {
+pub(super) struct UpdateCommand {
     /// The maximal number of videos to fetch for each subscription.
     #[arg(short, long)]
     max_backlog: Option<usize>,
diff --git a/crates/yt/src/commands/videos/implm.rs b/crates/yt/src/commands/videos/implm.rs
index 7c2ec8a..0441b31 100644
--- a/crates/yt/src/commands/videos/implm.rs
+++ b/crates/yt/src/commands/videos/implm.rs
@@ -8,7 +8,7 @@ use anyhow::{Context, Result};
 use futures::{TryStreamExt, stream::FuturesUnordered};
 
 impl VideosCommand {
-    pub(crate) async fn implm(self, app: &App) -> Result<()> {
+    pub(in crate::commands) async fn implm(self, app: &App) -> Result<()> {
         match self {
             VideosCommand::List {
                 search_query,
diff --git a/crates/yt/src/commands/videos/mod.rs b/crates/yt/src/commands/videos/mod.rs
index 93a11a1..298f13d 100644
--- a/crates/yt/src/commands/videos/mod.rs
+++ b/crates/yt/src/commands/videos/mod.rs
@@ -5,7 +5,7 @@ use crate::storage::db::extractor_hash::LazyExtractorHash;
 mod implm;
 
 #[derive(Subcommand, Clone, Debug)]
-pub(crate) enum VideosCommand {
+pub(super) enum VideosCommand {
     /// List the videos in the database
     #[command(visible_alias = "ls")]
     List {
diff --git a/crates/yt/src/commands/watch/implm/mod.rs b/crates/yt/src/commands/watch/implm/mod.rs
index 6aaa076..9eba858 100644
--- a/crates/yt/src/commands/watch/implm/mod.rs
+++ b/crates/yt/src/commands/watch/implm/mod.rs
@@ -28,7 +28,7 @@ mod playlist_handler;
 
 impl WatchCommand {
     #[allow(clippy::too_many_lines)]
-    pub(crate) async fn implm(self, app: Arc<App>) -> Result<()> {
+    pub(in crate::commands) async fn implm(self, app: Arc<App>) -> Result<()> {
         let WatchCommand {
             provide_ipc_socket,
             headless,
diff --git a/crates/yt/src/commands/watch/mod.rs b/crates/yt/src/commands/watch/mod.rs
index 8bae5c9..b106370 100644
--- a/crates/yt/src/commands/watch/mod.rs
+++ b/crates/yt/src/commands/watch/mod.rs
@@ -3,7 +3,7 @@ use clap::Parser;
 mod implm;
 
 #[derive(Parser, Debug)]
-pub(crate) struct WatchCommand {
+pub(super) struct WatchCommand {
     /// Print the path to an ipc socket for mpv control to stdout at startup.
     #[arg(long)]
     provide_ipc_socket: bool,