Struct InputPathHandler

Source
pub struct InputPathHandler {
    pub paths: Vec<PathBuf>,
    pub recursive: bool,
    pub file_extensions: Vec<String>,
}
Expand description

Universal input path processing structure for CLI commands.

InputPathHandler provides a unified interface for processing file and directory inputs across different SubX CLI commands. It supports multiple input sources, recursive directory scanning, and file extension filtering.

This handler is used by commands like match, convert, sync, and detect-encoding to provide consistent -i parameter functionality and directory processing behavior.

§Features

  • Multiple Input Sources: Supports multiple files and directories via -i parameter
  • Recursive Processing: Optional recursive directory scanning with --recursive flag
  • File Filtering: Filter files by extension for command-specific processing
  • Path Validation: Validates all input paths exist before processing
  • Cross-Platform: Handles both absolute and relative paths correctly

§Examples

§Basic Usage

use subx_cli::cli::InputPathHandler;
use std::path::PathBuf;


// Create handler from multiple paths
let paths = vec![file1, file2];
let handler = InputPathHandler::from_args(&paths, false)?
    .with_extensions(&["srt", "ass"]);

// Collect all matching files
let files = handler.collect_files()?;
assert_eq!(files.len(), 2);

§Directory Processing

use subx_cli::cli::InputPathHandler;
use std::path::PathBuf;


// Flat directory scanning (non-recursive)
let handler_flat = InputPathHandler::from_args(&[test_dir.to_path_buf()], false)?
    .with_extensions(&["srt"]);
let files_flat = handler_flat.collect_files()?;
assert_eq!(files_flat.len(), 1); // Only finds file1

// Recursive directory scanning
let handler_recursive = InputPathHandler::from_args(&[test_dir.to_path_buf()], true)?
    .with_extensions(&["srt"]);
let files_recursive = handler_recursive.collect_files()?;
assert_eq!(files_recursive.len(), 2); // Finds both file1 and file2

§Command Integration

use subx_cli::cli::{InputPathHandler, MatchArgs};

// Example of how commands use InputPathHandler
let handler = args.get_input_handler()?;
let files = handler.collect_files()?;
// Process files...

Fields§

§paths: Vec<PathBuf>

List of input paths (files and directories) to process

§recursive: bool

Whether to recursively scan subdirectories

§file_extensions: Vec<String>

File extension filters (lowercase, without dot)

Implementations§

Source§

impl InputPathHandler

Source

pub fn merge_paths_from_multiple_sources( optional_paths: &[Option<PathBuf>], multiple_paths: &[PathBuf], string_paths: &[String], ) -> Result<Vec<PathBuf>, SubXError>

Merge paths from multiple sources to create a unified path list

This method provides a unified interface for CLI commands to merge different types of path parameters into a single PathBuf vector.

§Arguments
  • optional_paths - Optional path list (e.g., path, input, video, subtitle, etc.)
  • multiple_paths - Multiple path list (e.g., input_paths)
  • string_paths - String format path list (e.g., file_paths)
§Returns

Returns the merged PathBuf vector, or an error if all inputs are empty

§Examples
use subx_cli::cli::InputPathHandler;
use std::path::PathBuf;

// Merge paths from different sources
let optional = vec![Some(PathBuf::from("single.srt"))];
let multiple = vec![PathBuf::from("dir1"), PathBuf::from("dir2")];
let strings = vec!["file1.srt".to_string(), "file2.ass".to_string()];

let merged = InputPathHandler::merge_paths_from_multiple_sources(
    &optional,
    &multiple,
    &strings
)?;

// merged now contains all paths
assert_eq!(merged.len(), 5);
Source

pub fn from_args( input_args: &[PathBuf], recursive: bool, ) -> Result<Self, SubXError>

Create InputPathHandler from command line arguments

Source

pub fn with_extensions(self, extensions: &[&str]) -> Self

Set supported file extensions (without dot)

Source

pub fn validate(&self) -> Result<(), SubXError>

Validate that all paths exist

Source

pub fn get_directories(&self) -> Vec<PathBuf>

Get all specified directory paths

This method returns all specified directory paths for commands that need to process directories one by one. If the specified path contains files, it will return the directory containing that file.

§Returns

Deduplicated list of directory paths

§Examples
use subx_cli::cli::InputPathHandler;
use std::path::PathBuf;


let paths = vec![file1.clone(), test_dir.to_path_buf()];
let handler = InputPathHandler::from_args(&paths, false)?;
let directories = handler.get_directories();

// Should contain test_dir (after deduplication)
assert_eq!(directories.len(), 1);
assert_eq!(directories[0], test_dir);
Source

pub fn collect_files(&self) -> Result<Vec<PathBuf>, SubXError>

Expand files and directories, collecting all files that match the filter conditions

Trait Implementations§

Source§

impl Clone for InputPathHandler

Source§

fn clone(&self) -> InputPathHandler

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InputPathHandler

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,