Just reformat the code

This commit is contained in:
Anas Elgarhy 2023-02-13 02:09:47 +02:00
parent 25cce99b80
commit 1ea44b528c
No known key found for this signature in database
GPG key ID: 0501802A1D496528
3 changed files with 14 additions and 15 deletions

View file

@ -1,8 +1,7 @@
use clap::Parser;
use cmus_notify::arguments::Arguments;
use cmus_notify::{
arguments,
settings::Settings,
cmus::{self, query::CmusQueryResponse, CmusError},
};
@ -13,17 +12,17 @@ macro_rules! sleep {
}
fn main() {
// Load the configs
let settings = Arguments::load_config_and_parse_args();
// Load the configs and parse the arguments, and combine them together.
let settings = Settings::load_config_and_parse_args();
// Build the command, or use the default. (to speed up the main loop, because we don't need to build it every time)
let mut query_command = cmus::build_query_command(
&args
&settings
.cmus_remote_bin_path
.unwrap_or("cmus-remote".to_string())
.as_str(),
&args.cmus_socket_address,
&args.cmus_socket_password,
&settings.cmus_socket_address,
&settings.cmus_socket_password,
);
// Initialize the buffer to store the response from cmus, to compare it with the next one.
@ -36,11 +35,11 @@ fn main() {
loop {
// Get the track info, and compare it with the previous one.
let Ok(response) = cmus::ping_cmus(&mut query_command) else {
if args.link {
if settings.link {
std::process::exit(0)
} else {
// If the track info is the same as the previous one, just sleep for a while and try again.
sleep!(args.interval);
sleep!(settings.interval);
continue;
}
};
@ -55,6 +54,6 @@ fn main() {
let changes = track.get_changes(&previous_track);
*/
sleep!(args.interval);
sleep!(settings.interval);
}
}

View file

@ -2,7 +2,7 @@
use std::path::Path;
pub mod arguments;
pub mod settings;
pub mod cmus;
/// Extracts the first embedded picture from an ID3 tag of an Audio file.

View file

@ -11,7 +11,7 @@ const DEFAULT_INTERVAL_TIME: u64 = 1000; // 1000 ms
#[derive(Parser, Debug, Serialize, Deserialize)]
#[command(author, about, version, long_about = None)]
pub struct Arguments {
pub struct Settings {
/// The notification timeout, in seconds
#[arg(short, long, default_value_t = NOTIFICATION_TIMEOUT)]
pub timeout: u8,
@ -150,7 +150,7 @@ pub struct Arguments {
pub no_use_external_lyrics: bool,
}
impl Default for Arguments {
impl Default for Settings {
fn default() -> Self {
Self {
timeout: NOTIFICATION_TIMEOUT,
@ -178,7 +178,7 @@ impl Default for Arguments {
}
}
impl Arguments {
impl Settings {
pub fn load_config_and_parse_args() -> Self {
// load config file
let cfg: Self = match confy::load("cmus-notify", "config") {
@ -190,7 +190,7 @@ impl Arguments {
};
// parse the args
let mut args = Arguments::parse();
let mut args = Settings::parse();
// Combine the config and args(the args will override the config)
if args.timeout == NOTIFICATION_TIMEOUT {