Skip to content

Commit

Permalink
Merge pull request #163 from 220111/default-config-fixes
Browse files Browse the repository at this point in the history
Default config file name fixes
  • Loading branch information
Radiicall authored Oct 25, 2024
2 parents 2393f16 + 4e93c23 commit b3fa50e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
6 changes: 3 additions & 3 deletions jellyfin-rpc-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ pub fn get_urls_path() -> Result<String, Box<dyn std::error::Error>> {
}
}

/// Find config.json in filesystem.
/// Find default config path (main.json) in filesystem.
///
/// This is to avoid the user having to specify a filepath on launch.
///
/// Default config path depends on OS
/// Windows: `%appdata%\jellyfin-rpc\config.json`
/// Linux/macOS: `~/.config/jellyfin-rpc/config.json`
/// Windows: `%appdata%\jellyfin-rpc\main.json`
/// Linux/macOS: `~/.config/jellyfin-rpc/main.json`
pub fn get_config_path() -> Result<String, Box<dyn std::error::Error>> {
debug!("Getting config path");
if cfg!(not(windows)) {
Expand Down
22 changes: 14 additions & 8 deletions jellyfin-rpc-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::Parser;
use colored::Colorize;
use config::{get_config_path, get_urls_path, Config};
use jellyfin_rpc::Client;
use log::{debug, error, info};
Expand Down Expand Up @@ -66,14 +67,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "updates")]
updates::checker();

let conf = Config::builder()
.load(
&args
.config
.unwrap_or(get_config_path().expect("default config path couldn't be determined")),
)
.expect("config not found")
.build();
let conf_path = &args
.config
.unwrap_or(get_config_path().expect("default config path couldn't be determined"));

let conf = match Config::builder().load(conf_path) {
Ok(file) => file.build(),
Err(error) => {
error!("Config file could not be loaded at path: {}", conf_path.red());
error!("{}", error);
error!("Please create a proper config file: {}", "https://github.com/Radiicall/jellyfin-rpc/wiki/Setup".green());
std::process::exit(1)
}
};

debug!("Creating jellyfin-rpc client builder");
let mut builder = Client::builder();
Expand Down

0 comments on commit b3fa50e

Please sign in to comment.