The fetched settings are only written into app state when nothing is already held there, so a refresh landing while the user has the settings prompt open cannot overwrite edits in progress. The fixtures give every field a distinct value. Settings whose fields all share one value cannot detect two of them being mapped to each other's keys.
123 lines
3.3 KiB
Rust
123 lines
3.3 KiB
Rust
use std::sync::Arc;
|
|
|
|
use anyhow::Result;
|
|
use clap::Subcommand;
|
|
use tokio::sync::Mutex;
|
|
|
|
use crate::{
|
|
app::App,
|
|
cli::{CliCommandHandler, Command},
|
|
network::{NetworkTrait, readarr_network::ReadarrEvent},
|
|
};
|
|
|
|
use super::ReadarrCommand;
|
|
|
|
#[cfg(test)]
|
|
#[path = "get_command_handler_tests.rs"]
|
|
mod get_command_handler_tests;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
|
|
pub enum ReadarrGetCommand {
|
|
#[command(about = "Get the shared settings for all indexers")]
|
|
AllIndexerSettings,
|
|
#[command(about = "Get detailed information for the author with the given ID")]
|
|
AuthorDetails {
|
|
#[arg(
|
|
long,
|
|
help = "The Readarr ID of the author whose details you wish to fetch",
|
|
required = true
|
|
)]
|
|
author_id: i64,
|
|
},
|
|
#[command(about = "Get detailed information for the book with the given ID")]
|
|
BookDetails {
|
|
#[arg(
|
|
long,
|
|
help = "The Readarr ID of the book whose details you wish to fetch",
|
|
required = true
|
|
)]
|
|
book_id: i64,
|
|
},
|
|
#[command(about = "Fetch the host config for your Readarr instance")]
|
|
HostConfig,
|
|
#[command(about = "Fetch the security config for your Readarr instance")]
|
|
SecurityConfig,
|
|
#[command(about = "Get the system status")]
|
|
SystemStatus,
|
|
}
|
|
|
|
impl From<ReadarrGetCommand> for Command {
|
|
fn from(value: ReadarrGetCommand) -> Self {
|
|
Command::Readarr(ReadarrCommand::Get(value))
|
|
}
|
|
}
|
|
|
|
pub(super) struct ReadarrGetCommandHandler<'a, 'b> {
|
|
_app: &'a Arc<Mutex<App<'b>>>,
|
|
command: ReadarrGetCommand,
|
|
network: &'a mut dyn NetworkTrait,
|
|
}
|
|
|
|
impl<'a, 'b> CliCommandHandler<'a, 'b, ReadarrGetCommand> for ReadarrGetCommandHandler<'a, 'b> {
|
|
fn with(
|
|
_app: &'a Arc<Mutex<App<'b>>>,
|
|
command: ReadarrGetCommand,
|
|
network: &'a mut dyn NetworkTrait,
|
|
) -> Self {
|
|
ReadarrGetCommandHandler {
|
|
_app,
|
|
command,
|
|
network,
|
|
}
|
|
}
|
|
|
|
async fn handle(self) -> Result<String> {
|
|
let result = match self.command {
|
|
ReadarrGetCommand::AllIndexerSettings => {
|
|
let resp = self
|
|
.network
|
|
.handle_network_event(ReadarrEvent::GetAllIndexerSettings.into())
|
|
.await?;
|
|
serde_json::to_string_pretty(&resp)?
|
|
}
|
|
ReadarrGetCommand::AuthorDetails { author_id } => {
|
|
let resp = self
|
|
.network
|
|
.handle_network_event(ReadarrEvent::GetAuthorDetails(author_id).into())
|
|
.await?;
|
|
serde_json::to_string_pretty(&resp)?
|
|
}
|
|
ReadarrGetCommand::BookDetails { book_id } => {
|
|
let resp = self
|
|
.network
|
|
.handle_network_event(ReadarrEvent::GetBookDetails(book_id).into())
|
|
.await?;
|
|
serde_json::to_string_pretty(&resp)?
|
|
}
|
|
ReadarrGetCommand::HostConfig => {
|
|
let resp = self
|
|
.network
|
|
.handle_network_event(ReadarrEvent::GetHostConfig.into())
|
|
.await?;
|
|
serde_json::to_string_pretty(&resp)?
|
|
}
|
|
ReadarrGetCommand::SecurityConfig => {
|
|
let resp = self
|
|
.network
|
|
.handle_network_event(ReadarrEvent::GetSecurityConfig.into())
|
|
.await?;
|
|
serde_json::to_string_pretty(&resp)?
|
|
}
|
|
ReadarrGetCommand::SystemStatus => {
|
|
let resp = self
|
|
.network
|
|
.handle_network_event(ReadarrEvent::GetStatus.into())
|
|
.await?;
|
|
serde_json::to_string_pretty(&resp)?
|
|
}
|
|
};
|
|
|
|
Ok(result)
|
|
}
|
|
}
|