Skip to content

Commit

Permalink
add more doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eth0net committed May 1, 2024
1 parent e1eeb3d commit 71dee34
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::PathBuf;
#[derive(Clone, Debug, Default, Parser)]
#[command(version, author, about)]
#[group(id = "noisy", multiple = true)]
/// Arguments for the application binary.
pub struct Args {
/// A list of files or directories to process.
///
Expand Down
7 changes: 4 additions & 3 deletions src/comic.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use std::fmt::Display;
use std::str::FromStr;

pub use error::ComicError;
pub use format::{Format, FormatError};

mod error;
mod format;
mod parse;
mod regex;

pub use error::ComicError;
pub use format::{Format, FormatError};

#[derive(Debug, PartialEq, Eq)]
/// A comic.
pub struct Comic {
// Name of the series.
//
Expand Down
3 changes: 2 additions & 1 deletion src/comic/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use std::num::ParseIntError;

use thiserror::Error;

use super::FormatError;
use crate::comic::FormatError;

#[derive(Debug, Error)]
/// Errors that can occur when parsing a comic book file name.
pub enum ComicError {
#[error("invalid input: no capture groups matched")]
GetCaptures,
Expand Down
6 changes: 6 additions & 0 deletions src/comic/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ use thiserror::Error;

#[derive(Debug, Error)]
#[error("invalid format")]
/// Error that occurs when parsing a comic book format.
pub struct FormatError;

#[derive(Debug, PartialEq, Eq)]
/// The format of a comic book file.
pub enum Format {
/// 7z archive.
Cb7,
/// Rar archive.
Cbr,
/// Tar archive.
Cbt,
/// Zip archive.
Cbz,
}

Expand Down
1 change: 1 addition & 0 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use log::LevelFilter;

use crate::args::Args;

/// Initialize the logger.
pub fn init(args: &Args) {
let mut level = match args.verbose {
0 => LevelFilter::Error,
Expand Down
21 changes: 13 additions & 8 deletions src/process/processor.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
use std::{
fs,
path::{Path, PathBuf},
};
use std::fs;
use std::path::{Path, PathBuf};

use anyhow::Context;

use crate::comic::Comic;

use super::ProcessorSettings;
use crate::process::ProcessorSettings;

#[derive(Default)]
/// Processor for organising comic files
pub struct Processor {
/// Settings for the processor
settings: ProcessorSettings,
}

impl Processor {
/// Create a new Processor instance with the provided settings
pub fn new(settings: ProcessorSettings) -> Processor {
Self { settings }
}

/// Process the provided targets
pub fn process(&self, targets: Vec<PathBuf>) -> anyhow::Result<()> {
log::trace!("processing targets");

Expand Down Expand Up @@ -56,8 +57,11 @@ impl Processor {

Ok(())
}
}

pub(crate) fn process_dir(&self, path: &Path) -> anyhow::Result<()> {
impl Processor {
/// Process the provided directory
fn process_dir(&self, path: &Path) -> anyhow::Result<()> {
log::debug!("processing dir: {}", path.display());

let directory = path
Expand Down Expand Up @@ -117,7 +121,8 @@ impl Processor {
Ok(())
}

pub(crate) fn process_file(&self, path: &Path) -> anyhow::Result<()> {
/// Process the provided file
fn process_file(&self, path: &Path) -> anyhow::Result<()> {
log::debug!("processing file: {}", path.display());

let name = path.file_name().context("getting file name")?;
Expand Down
10 changes: 10 additions & 0 deletions src/process/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@ use std::path::PathBuf;
use crate::args::Args;

#[derive(Default)]
/// Settings for the processor
pub struct ProcessorSettings {
/// The output directory for the processed files
pub output: PathBuf,
/// Whether to output files in series subdirectories
pub series: bool,
/// Whether to move files instead of copying them
pub move_files: bool,
/// Whether to perform a dry run
pub dry_run: bool,
/// Whether to exit after processing
pub exit: bool,
/// Whether to force overwrite of existing files
pub force: bool,
/// Whether to process files recursively
pub recursive: bool,
}

impl ProcessorSettings {
/// Create a new ProcessorSettings instance with default values
pub fn new() -> ProcessorSettings {
ProcessorSettings::default()
}

/// Create a new ProcessorSettings instance from the provided Args
pub fn from_args(args: &Args) -> ProcessorSettings {
ProcessorSettings {
output: args.output.clone(),
Expand Down

0 comments on commit 71dee34

Please sign in to comment.