From d537eb328fae72856c143c1c6c73c49a06d8d55e Mon Sep 17 00:00:00 2001 From: chaos Date: Thu, 19 Oct 2023 17:28:05 +0100 Subject: [PATCH] move command args into their respective files --- src/args.rs | 87 ++++----------------------------------- src/commands/copy.rs | 18 +++++++- src/commands/genhtml.rs | 13 +++++- src/commands/get_tags.rs | 9 +++- src/commands/process.rs | 14 ++++++- src/commands/set_tags.rs | 10 ++++- src/commands/transcode.rs | 15 ++++++- 7 files changed, 82 insertions(+), 84 deletions(-) diff --git a/src/args.rs b/src/args.rs index 2f5eb90..2fe2581 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,4 +1,6 @@ -use clap::{Args, Parser, Subcommand}; +use clap::{Parser, Subcommand}; + +use crate::commands; #[derive(Debug, Parser)] #[clap()] @@ -9,81 +11,10 @@ pub struct CLIArgs { #[derive(Debug, Clone, Subcommand)] pub enum Commands { - Process(ProcessCommandArgs), - Genhtml(GenHTMLCommandArgs), - Transcode(TranscodeCommandArgs), - Copy(CopyCommandArgs), - SetTags(SetTagsCommandArgs), - GetTags(GetTagsCommandArgs), -} - -#[derive(Debug, Clone, Args)] -pub struct ProcessCommandArgs { - pub source: String, - #[clap(long)] - pub dry_run: bool, - #[clap(long)] - pub skip_replaygain: bool, - #[clap(long)] - pub force_replaygain: bool, - #[clap(long)] - pub replaygain_threads: Option, -} - -#[derive(Debug, Clone, Args)] -pub struct GenHTMLCommandArgs { - pub source: String, - pub dest: String, - #[clap(long, default_value = "musicutil")] - pub title: String, - #[clap(long, default_value = "generated by musicutil")] - pub description: String, - #[clap(long)] - pub link_base: Option, -} - -#[derive(Debug, Clone, Args)] -pub struct TranscodeCommandArgs { - pub source: String, - pub dest: String, - #[clap(long)] - pub transcode_preset: Option, - #[clap(long)] - pub transcode_config: Option, - #[clap(long)] - pub ignore_extension: bool, - #[clap(long)] - pub hide_progress: bool, -} - -#[derive(Debug, Clone, Args)] -pub struct CopyCommandArgs { - pub source: String, - pub dest: String, - #[clap(long)] - pub transcode_preset: Option, - #[clap(long)] - pub transcode_config: Option, - #[clap(long)] - pub threads: Option, - #[clap(long)] - pub no_skip_existing: bool, - #[clap(long)] - pub single_directory: bool, -} - -#[derive(Debug, Clone, Args)] -pub struct SetTagsCommandArgs { - pub files: Vec, - #[clap(long)] - pub title: Option, - #[clap(long)] - pub artist: Option, -} - -#[derive(Debug, Clone, Args)] -pub struct GetTagsCommandArgs { - pub files: Vec, - #[clap(long)] - pub json: bool, + Process(commands::process::ProcessCommandArgs), + Genhtml(commands::genhtml::GenHTMLCommandArgs), + Transcode(commands::transcode::TranscodeCommandArgs), + Copy(commands::copy::CopyCommandArgs), + SetTags(commands::set_tags::SetTagsCommandArgs), + GetTags(commands::get_tags::GetTagsCommandArgs), } diff --git a/src/commands/copy.rs b/src/commands/copy.rs index 8cba9e4..b54b567 100644 --- a/src/commands/copy.rs +++ b/src/commands/copy.rs @@ -9,7 +9,7 @@ use std::{ }; use crate::{ - args::{CLIArgs, CopyCommandArgs}, + args::CLIArgs, types::File, utils::{ formats::get_format_handler, @@ -22,6 +22,22 @@ use crate::{ }, }; +#[derive(Debug, Clone, clap::Args)] +pub struct CopyCommandArgs { + pub source: String, + pub dest: String, + #[clap(long)] + pub transcode_preset: Option, + #[clap(long)] + pub transcode_config: Option, + #[clap(long)] + pub threads: Option, + #[clap(long)] + pub no_skip_existing: bool, + #[clap(long)] + pub single_directory: bool, +} + pub fn copy_command( _args: CLIArgs, copy_args: &CopyCommandArgs, diff --git a/src/commands/genhtml.rs b/src/commands/genhtml.rs index 341aa0b..e29d28f 100644 --- a/src/commands/genhtml.rs +++ b/src/commands/genhtml.rs @@ -1,5 +1,4 @@ use crate::args::CLIArgs; -use crate::args::GenHTMLCommandArgs; use crate::types::File; use crate::utils::formats::get_format_handler; use crate::utils::scan_for_music; @@ -10,6 +9,18 @@ use std::io::Write; use html_escape::encode_text; use urlencoding::encode as url_encode; +#[derive(Debug, Clone, clap::Args)] +pub struct GenHTMLCommandArgs { + pub source: String, + pub dest: String, + #[clap(long, default_value = "musicutil")] + pub title: String, + #[clap(long, default_value = "generated by musicutil")] + pub description: String, + #[clap(long)] + pub link_base: Option, +} + fn table_for_files(files: Vec, includes_path: bool, link_base: &Option) -> String { let mut html_content = String::new(); diff --git a/src/commands/get_tags.rs b/src/commands/get_tags.rs index 39f540a..3447ed6 100644 --- a/src/commands/get_tags.rs +++ b/src/commands/get_tags.rs @@ -4,10 +4,17 @@ use std::path::PathBuf; use serde::Serialize; use crate::args::CLIArgs; -use crate::args::GetTagsCommandArgs; use crate::types::File; use crate::utils::formats::get_format_handler; +#[derive(Debug, Clone, clap::Args)] +pub struct GetTagsCommandArgs { + pub files: Vec, + #[clap(long)] + pub json: bool, +} + + #[derive(Debug, Clone, Serialize)] struct Tags { title: String, diff --git a/src/commands/process.rs b/src/commands/process.rs index dc33c91..ed56c58 100644 --- a/src/commands/process.rs +++ b/src/commands/process.rs @@ -3,13 +3,25 @@ use std::sync::Mutex; use std::thread::scope; use crate::args::CLIArgs; -use crate::args::ProcessCommandArgs; use crate::types::File; use crate::utils::ascii_reduce::reduce_to_ascii; use crate::utils::formats::get_format_handler; use crate::utils::replaygain::analyze_replaygain; use crate::utils::scan_for_music; +#[derive(Debug, Clone, clap::Args)] +pub struct ProcessCommandArgs { + pub source: String, + #[clap(long)] + pub dry_run: bool, + #[clap(long)] + pub skip_replaygain: bool, + #[clap(long)] + pub force_replaygain: bool, + #[clap(long)] + pub replaygain_threads: Option, +} + fn rename_file(process_args: &ProcessCommandArgs, file: &mut File) { let title = &file.info.tags.title; let artist = &file.info.tags.artist; diff --git a/src/commands/set_tags.rs b/src/commands/set_tags.rs index dd25095..799039f 100644 --- a/src/commands/set_tags.rs +++ b/src/commands/set_tags.rs @@ -1,10 +1,18 @@ use std::path::PathBuf; use crate::args::CLIArgs; -use crate::args::SetTagsCommandArgs; use crate::types::File; use crate::utils::formats::get_format_handler; +#[derive(Debug, Clone, clap::Args)] +pub struct SetTagsCommandArgs { + pub files: Vec, + #[clap(long)] + pub title: Option, + #[clap(long)] + pub artist: Option, +} + pub fn set_tags_command( _args: CLIArgs, add_tags_args: &SetTagsCommandArgs, diff --git a/src/commands/transcode.rs b/src/commands/transcode.rs index 19c5ccb..20b94cf 100644 --- a/src/commands/transcode.rs +++ b/src/commands/transcode.rs @@ -5,12 +5,25 @@ use std::thread; use std::thread::JoinHandle; use crate::args::CLIArgs; -use crate::args::TranscodeCommandArgs; use crate::types::File; use crate::utils::transcoder::presets::print_presets; use crate::utils::transcoder::presets::transcode_preset_or_config; use crate::utils::transcoder::transcode; +#[derive(Debug, Clone, clap::Args)] +pub struct TranscodeCommandArgs { + pub source: String, + pub dest: String, + #[clap(long)] + pub transcode_preset: Option, + #[clap(long)] + pub transcode_config: Option, + #[clap(long)] + pub ignore_extension: bool, + #[clap(long)] + pub hide_progress: bool, +} + pub fn transcode_command( _args: CLIArgs, transcode_args: &TranscodeCommandArgs,