move command args into their respective files

This commit is contained in:
chaos 2023-10-19 17:28:05 +01:00
parent 2f5f493f9b
commit d537eb328f
No known key found for this signature in database
7 changed files with 82 additions and 84 deletions

View file

@ -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<u32>,
}
#[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<String>,
}
#[derive(Debug, Clone, Args)]
pub struct TranscodeCommandArgs {
pub source: String,
pub dest: String,
#[clap(long)]
pub transcode_preset: Option<String>,
#[clap(long)]
pub transcode_config: Option<String>,
#[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<String>,
#[clap(long)]
pub transcode_config: Option<String>,
#[clap(long)]
pub threads: Option<u32>,
#[clap(long)]
pub no_skip_existing: bool,
#[clap(long)]
pub single_directory: bool,
}
#[derive(Debug, Clone, Args)]
pub struct SetTagsCommandArgs {
pub files: Vec<String>,
#[clap(long)]
pub title: Option<String>,
#[clap(long)]
pub artist: Option<String>,
}
#[derive(Debug, Clone, Args)]
pub struct GetTagsCommandArgs {
pub files: Vec<String>,
#[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),
}

View file

@ -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<String>,
#[clap(long)]
pub transcode_config: Option<String>,
#[clap(long)]
pub threads: Option<u32>,
#[clap(long)]
pub no_skip_existing: bool,
#[clap(long)]
pub single_directory: bool,
}
pub fn copy_command(
_args: CLIArgs,
copy_args: &CopyCommandArgs,

View file

@ -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<String>,
}
fn table_for_files(files: Vec<File>, includes_path: bool, link_base: &Option<String>) -> String {
let mut html_content = String::new();

View file

@ -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<String>,
#[clap(long)]
pub json: bool,
}
#[derive(Debug, Clone, Serialize)]
struct Tags {
title: String,

View file

@ -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<u32>,
}
fn rename_file(process_args: &ProcessCommandArgs, file: &mut File) {
let title = &file.info.tags.title;
let artist = &file.info.tags.artist;

View file

@ -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<String>,
#[clap(long)]
pub title: Option<String>,
#[clap(long)]
pub artist: Option<String>,
}
pub fn set_tags_command(
_args: CLIArgs,
add_tags_args: &SetTagsCommandArgs,

View file

@ -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<String>,
#[clap(long)]
pub transcode_config: Option<String>,
#[clap(long)]
pub ignore_extension: bool,
#[clap(long)]
pub hide_progress: bool,
}
pub fn transcode_command(
_args: CLIArgs,
transcode_args: &TranscodeCommandArgs,