From 61ce0468c6f8a3932f09df1154b3e32b0b913a9a Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Thu, 31 Oct 2024 14:53:49 -0600 Subject: [PATCH] Added --config and --disable-terminal-size-checks flags to make the demo work properly [skip ci] --- Dockerfile | 2 +- README.md | 9 +++++++++ src/main.rs | 50 ++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 87b7851..62d0ecd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,4 @@ FROM debian:stable-slim # Copy the compiled binary from the builder container COPY --from=builder --chown=nonroot:nonroot /usr/src/managarr-temp/managarr /usr/local/bin -ENTRYPOINT [ "/usr/local/bin/managarr" ] +ENTRYPOINT [ "/usr/local/bin/managarr", "--disable-terminal-size-checks" ] diff --git a/README.md b/README.md index c5bcd66..74b3683 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,15 @@ $HOME/Library/Application Support/managarr/config.yml %APPDATA%/Roaming/managarr/config.yml ``` +## Specify Configuration File +It can sometimes be useful to specify the configuration file you wish to use. This is useful in cases +where you may have more than one instance of a given Servarr running. Thus, you can specify the +config file using the `--config` flag: + +```shell +managarr --config /path/to/config.yml +``` + ### Example Configuration: ```yaml radarr: diff --git a/src/main.rs b/src/main.rs index 504a4f0..917db71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,16 @@ #![warn(rust_2018_idioms)] +use std::fs::File; +use std::io::BufReader; use std::panic::PanicHookInfo; +use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::{io, panic, process}; use anyhow::anyhow; use anyhow::Result; +use app::AppConfig; use clap::{ command, crate_authors, crate_description, crate_name, crate_version, CommandFactory, Parser, }; @@ -62,6 +66,22 @@ static MIN_TERM_HEIGHT: u16 = 40; struct Cli { #[command(subcommand)] command: Option, + #[arg( + long, + global = true, + value_parser, + help = "The Managarr configuration file to use" + )] + config: Option, + #[arg(long, global = true, help = "Disable the terminal size checks")] + disable_terminal_size_checks: bool, +} + +fn load_config(path: &str) -> Result { + let file = File::open(path).map_err(|e| anyhow!(e))?; + let reader = BufReader::new(file); + let config = serde_yaml::from_reader(reader)?; + Ok(config) } #[tokio::main] @@ -73,7 +93,11 @@ async fn main() -> Result<()> { let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); let args = Cli::parse(); - let config = confy::load("managarr", "config")?; + let config = if let Some(ref config_file) = args.config { + load_config(config_file.to_str().expect("Invalid config file specified"))? + } else { + confy::load("managarr", "config")? + }; let (sync_network_tx, sync_network_rx) = mpsc::channel(500); let cancellation_token = CancellationToken::new(); let ctrlc_cancellation_token = cancellation_token.clone(); @@ -110,7 +134,7 @@ async fn main() -> Result<()> { None => { let app_nw = Arc::clone(&app); std::thread::spawn(move || start_networking(sync_network_rx, &app_nw, cancellation_token)); - start_ui(&app).await?; + start_ui(&app, !args.disable_terminal_size_checks).await?; } } @@ -132,16 +156,18 @@ async fn start_networking( } } -async fn start_ui(app: &Arc>>) -> Result<()> { - let (width, height) = size()?; - if width < MIN_TERM_WIDTH || height < MIN_TERM_HEIGHT { - return Err(anyhow!( - "Terminal too small. Minimum size required: {}x{}; current terminal size: {}x{}", - MIN_TERM_WIDTH, - MIN_TERM_HEIGHT, - width, - height - )); +async fn start_ui(app: &Arc>>, check_terminal_size: bool) -> Result<()> { + if check_terminal_size { + let (width, height) = size()?; + if width < MIN_TERM_WIDTH || height < MIN_TERM_HEIGHT { + return Err(anyhow!( + "Terminal too small. Minimum size required: {}x{}; current terminal size: {}x{}", + MIN_TERM_WIDTH, + MIN_TERM_HEIGHT, + width, + height + )); + } } let mut stdout = io::stdout();