tagkit.cli.file_resolver

Module Contents

Classes

FileResolver

Resolves file paths from a string, glob, or regex pattern. Raises an error if both glob_mode and regex_mode are set.

API

class tagkit.cli.file_resolver.FileResolver(file_or_pattern: str, glob_mode: bool = False, regex_mode: bool = False)

Resolves file paths from a string, glob, or regex pattern. Raises an error if both glob_mode and regex_mode are set.

Args:

file_or_pattern (str): File path, glob, or regex pattern. glob_mode (bool): If True, use glob matching. regex_mode (bool): If True, use regex matching.

Example:

Dir contents: ‘foo.txt’, ‘image1.jpg’, ‘image10.jpg’, ‘image2.jpg’, ‘image3.jpg’]

>>> resolver = FileResolver("image1.jpg")
>>> [path.name for path in resolver.files]
['image1.jpg']
>>> resolver = FileResolver("image1*.jpg", glob_mode=True)
>>> [path.name for path in resolver.files]
['image1.jpg', 'image10.jpg']
>>> resolver = FileResolver("image[12].jpg", regex_mode=True)
>>> [path.name for path in resolver.files]
['image1.jpg', 'image2.jpg']

Initialization

_resolve(file_or_pattern: str, glob_mode: bool, regex_mode: bool) List[pathlib.Path]

Resolve files based on the provided pattern and mode. Raises a Typer.BadParameter if both glob_mode and regex_mode are set.

Args:

file_or_pattern (str): File path, glob, or regex pattern. glob_mode (bool): If True, use glob matching. regex_mode (bool): If True, use regex matching.

Returns:

List[Path]: List of resolved file paths.

_resolve_direct_file(file_path: str) List[pathlib.Path]

Resolve a direct file path.

Args:

file_path (str): Path to a file.

Returns:

List[Path]: List containing the file path if it exists, empty list otherwise.

_resolve_glob(pattern: str) List[pathlib.Path]

Resolve files using glob pattern matching.

Args:

pattern (str): Glob pattern to match.

Returns:

List[Path]: List of paths matching the glob pattern.

_resolve_regex(pattern: str) List[pathlib.Path]

Resolve files using regex pattern matching.

Args:

pattern (str): Regex pattern to match.

Returns:

List[Path]: List of paths matching the regex pattern.