feat(cli): Added a spinner to the CLI for long running commands like fetching releases

This commit is contained in:
2024-11-20 19:33:40 -07:00
parent f5631376af
commit 34157ef32f
19 changed files with 717 additions and 271 deletions
+9 -9
View File
@@ -7,7 +7,6 @@ use tokio::sync::Mutex;
use crate::{
app::App,
cli::{CliCommandHandler, Command},
execute_network_event,
network::{sonarr_network::SonarrEvent, NetworkTrait},
};
@@ -55,16 +54,17 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrDeleteCommand> for SonarrDeleteComm
}
}
async fn handle(self) -> Result<()> {
match self.command {
async fn handle(self) -> Result<String> {
let resp = match self.command {
SonarrDeleteCommand::BlocklistItem { blocklist_item_id } => {
execute_network_event!(
self,
SonarrEvent::DeleteBlocklistItem(Some(blocklist_item_id))
);
let resp = self
.network
.handle_network_event((SonarrEvent::DeleteBlocklistItem(Some(blocklist_item_id))).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
}
};
Ok(())
Ok(resp)
}
}
+34 -11
View File
@@ -7,7 +7,6 @@ use tokio::sync::Mutex;
use crate::{
app::App,
cli::{CliCommandHandler, Command},
execute_network_event,
network::{sonarr_network::SonarrEvent, NetworkTrait},
};
@@ -72,28 +71,52 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrGetCommand> for SonarrGetCommandHan
}
}
async fn handle(self) -> Result<()> {
match self.command {
async fn handle(self) -> Result<String> {
let result = match self.command {
SonarrGetCommand::AllIndexerSettings => {
execute_network_event!(self, SonarrEvent::GetAllIndexerSettings);
let resp = self
.network
.handle_network_event((SonarrEvent::GetAllIndexerSettings).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrGetCommand::EpisodeDetails { episode_id } => {
execute_network_event!(self, SonarrEvent::GetEpisodeDetails(Some(episode_id)));
let resp = self
.network
.handle_network_event((SonarrEvent::GetEpisodeDetails(Some(episode_id))).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrGetCommand::HostConfig => {
execute_network_event!(self, SonarrEvent::GetHostConfig);
let resp = self
.network
.handle_network_event((SonarrEvent::GetHostConfig).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrGetCommand::SecurityConfig => {
execute_network_event!(self, SonarrEvent::GetSecurityConfig);
let resp = self
.network
.handle_network_event((SonarrEvent::GetSecurityConfig).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrGetCommand::SeriesDetails { series_id } => {
execute_network_event!(self, SonarrEvent::GetSeriesDetails(Some(series_id)));
let resp = self
.network
.handle_network_event((SonarrEvent::GetSeriesDetails(Some(series_id))).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrGetCommand::SystemStatus => {
execute_network_event!(self, SonarrEvent::GetStatus);
let resp = self
.network
.handle_network_event((SonarrEvent::GetStatus).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
}
};
Ok(())
Ok(result)
}
}
+51 -18
View File
@@ -7,7 +7,6 @@ use tokio::sync::Mutex;
use crate::{
app::App,
cli::{CliCommandHandler, Command},
execute_network_event,
network::{sonarr_network::SonarrEvent, NetworkTrait},
};
@@ -91,22 +90,42 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrListCommand> for SonarrListCommandH
}
}
async fn handle(self) -> Result<()> {
match self.command {
async fn handle(self) -> Result<String> {
let result = match self.command {
SonarrListCommand::Blocklist => {
execute_network_event!(self, SonarrEvent::GetBlocklist);
let resp = self
.network
.handle_network_event((SonarrEvent::GetBlocklist).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrListCommand::Downloads => {
execute_network_event!(self, SonarrEvent::GetDownloads);
let resp = self
.network
.handle_network_event((SonarrEvent::GetDownloads).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrListCommand::Episodes { series_id } => {
execute_network_event!(self, SonarrEvent::GetEpisodes(Some(series_id)));
let resp = self
.network
.handle_network_event((SonarrEvent::GetEpisodes(Some(series_id))).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrListCommand::History { events: items } => {
execute_network_event!(self, SonarrEvent::GetHistory(Some(items)));
let resp = self
.network
.handle_network_event((SonarrEvent::GetHistory(Some(items))).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrListCommand::Indexers => {
execute_network_event!(self, SonarrEvent::GetIndexers);
let resp = self
.network
.handle_network_event((SonarrEvent::GetIndexers).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrListCommand::Logs {
events,
@@ -120,27 +139,41 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrListCommand> for SonarrListCommandH
if output_in_log_format {
let log_lines = self.app.lock().await.data.sonarr_data.logs.items.clone();
let json = serde_json::to_string_pretty(&log_lines)?;
println!("{}", json);
serde_json::to_string_pretty(&log_lines)?
} else {
let json = serde_json::to_string_pretty(&logs)?;
println!("{}", json);
serde_json::to_string_pretty(&logs)?
}
}
SonarrListCommand::QualityProfiles => {
execute_network_event!(self, SonarrEvent::GetQualityProfiles);
let resp = self
.network
.handle_network_event((SonarrEvent::GetQualityProfiles).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrListCommand::QueuedEvents => {
execute_network_event!(self, SonarrEvent::GetQueuedEvents);
let resp = self
.network
.handle_network_event((SonarrEvent::GetQueuedEvents).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrListCommand::Series => {
execute_network_event!(self, SonarrEvent::ListSeries);
let resp = self
.network
.handle_network_event((SonarrEvent::ListSeries).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrListCommand::SeriesHistory { series_id } => {
execute_network_event!(self, SonarrEvent::GetSeriesHistory(Some(series_id)));
let resp = self
.network
.handle_network_event((SonarrEvent::GetSeriesHistory(Some(series_id))).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
}
};
Ok(())
Ok(result)
}
}
+21 -11
View File
@@ -9,7 +9,6 @@ use tokio::sync::Mutex;
use crate::{
app::App,
execute_network_event,
network::{sonarr_network::SonarrEvent, NetworkTrait},
};
@@ -91,8 +90,8 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, '
}
}
async fn handle(self) -> Result<()> {
match self.command {
async fn handle(self) -> Result<String> {
let result = match self.command {
SonarrCommand::Delete(delete_command) => {
SonarrDeleteCommandHandler::with(self.app, delete_command, self.network)
.handle()
@@ -113,24 +112,35 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, '
.network
.handle_network_event(SonarrEvent::GetBlocklist.into())
.await?;
execute_network_event!(self, SonarrEvent::ClearBlocklist);
let resp = self
.network
.handle_network_event(SonarrEvent::ClearBlocklist.into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrCommand::ManualEpisodeSearch { episode_id } => {
println!("Searching for episode releases. This may take a minute...");
execute_network_event!(self, SonarrEvent::GetEpisodeReleases(Some(episode_id)));
let resp = self
.network
.handle_network_event(SonarrEvent::GetEpisodeReleases(Some(episode_id)).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrCommand::ManualSeasonSearch {
series_id,
season_number,
} => {
println!("Searching for season releases. This may take a minute...");
execute_network_event!(
self,
SonarrEvent::GetSeasonReleases(Some((series_id, season_number)))
);
let resp = self
.network
.handle_network_event(
SonarrEvent::GetSeasonReleases(Some((series_id, season_number))).into(),
)
.await?;
serde_json::to_string_pretty(&resp)?
}
}
};
Ok(())
Ok(result)
}
}