refactor(config): remove global config and pass as referenced

This commit is contained in:
Alexander Navarro 2024-07-19 16:02:56 -04:00
parent 9cec453498
commit 940093d599
7 changed files with 138 additions and 108 deletions

View file

@ -1,15 +1,10 @@
use clap::{Parser, Subcommand};
use lazy_static::lazy_static;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::str::FromStr;
use crate::grpc;
lazy_static! {
pub static ref CONFIG: Config = Config::new();
}
#[derive(Debug)]
pub enum ConfigMode {
Server,
@ -22,6 +17,12 @@ pub enum Commands {
Start {
#[arg(help = "Directory to scan for files", default_value = ".")]
base_path: PathBuf,
#[arg(
long,
help = "The value 1.0 is the “normal” volume. Any value other than 1.0 will multiply each sample by this value.",
default_value = "1.0"
)]
volume: f32,
},
/// Resume the playback
Play,
@ -52,13 +53,6 @@ struct Args {
#[arg(short, long, help = "the port to bind to", default_value = "50051")]
port: u16,
#[arg(
long,
help = "The value 1.0 is the “normal” volume. Any value other than 1.0 will multiply each sample by this value.",
default_value = "1.0"
)]
volume: f32,
}
#[derive(Debug)]
@ -85,7 +79,6 @@ impl Config {
let mut config = Self::default();
config.address = SocketAddr::from_str(format!("[::1]:{}", cli.port).as_str()).unwrap();
config.volume = cli.volume;
config.command = cli.cmd;
if grpc::is_socket_in_use(config.address) {