Skip to content

feat: add file and directory operation builtins (ls, mkdir, rmdir, touch, cat) - #2

Merged
podlLev merged 7 commits into
mainfrom
feature/file-directory-operations
Jul 1, 2026
Merged

podlLev merged 7 commits into
mainfrom
feature/file-directory-operations

Conversation

@podlLev

@podlLev podlLev commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

Implements core file and directory operation builtins, along with a refactor to centralize builtin registration via a BuiltinFactory enum.

Changes

New Builtins

  • ls — lists directory contents of current or specified directory, sorted alphabetically
  • mkdir — creates directories, including intermediate parents automatically
  • rmdir — removes empty directories with clear validation errors
  • touch — creates empty files or updates last-modified timestamp,
    creating intermediate parent directories if needed
  • cat — displays file contents, using try-with-resources to prevent file handle leaks

Refactoring

  • Mark all singleton builtin classes as final with @NoArgsConstructor(access = AccessLevel.PRIVATE) via Lombok
  • Introduce BuiltinFactory enum with two constructor overloads (singleton vs environment-dependent) to centralize builtin registration
  • Simplify CommandRegistry to register all builtins via BuiltinFactory.values() — adding a new builtin now requires a single line in one place

Testing

Manually verified:

  • ls lists current directory and accepts an optional path argument
  • mkdir creates nested directories in a single call
  • rmdir rejects non-empty directories and non-existent paths
  • touch creates new files and updates timestamps on existing ones
  • cat displays file contents and handles missing files gracefully

podlLev added 7 commits July 1, 2026 09:28
- Add LsBuiltin to list directory contents of current or specified directory
- Sort entries alphabetically, case-insensitive
- Handle missing or invalid directory with a clear error message
- Register ls in CommandRegistry
…Lombok

- Mark all singleton builtin classes as final to prevent subclassing
- Replace explicit private constructors with @NoArgsConstructor(access = AccessLevel.PRIVATE)
- Add MkdirBuiltin to create directories, supporting multiple arguments
- Use mkdirs() to create intermediate parent directories automatically
- Handle existing paths and creation failures with clear error messages
- Register mkdir in CommandRegistry
- Add RmdirBuiltin to remove empty directories, supporting multiple arguments
- Handle missing paths, non-directories, and non-empty directories with clear error messages
- Register rmdir in CommandRegistry
- Add TouchBuiltin to create empty files or update last-modified timestamp
- Create intermediate parent directories if they don't exist
- Handle multiple arguments and IO errors with clear error messages
- Register touch in CommandRegistry
- Add CatBuiltin to display file contents line by line
- Use try-with-resources on Files.lines() to prevent file handle leaks
- Handle multiple file arguments and IO errors with clear error messages
- Register cat in CommandRegistry
…tration

- Add BuiltinFactory enum with two constructors: one for singletons,
  one for environment-dependent builtins
- Simplify CommandRegistry to register builtins via BuiltinFactory.values()
- Adding a new builtin now requires a single line in BuiltinFactory
@podlLev podlLev self-assigned this Jul 1, 2026
@podlLev podlLev added the enhancement New feature or request label Jul 1, 2026
@podlLev
podlLev merged commit 170e93a into main Jul 1, 2026
@podlLev
podlLev deleted the feature/file-directory-operations branch July 1, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant