Project Overview
List is built as a modular Swift package with clear separation of concerns. The project is organized into three main modules that work together to provide a fast, feature-rich file listing tool.sls
Executable TargetEntry point for the CLI application
SwiftListCLI
CLI ModuleCommand-line interface and argument parsing
SwiftListCore
Core LibraryBusiness logic and file system operations
Module Structure
Dependency Graph
Module Responsibilities
- sls (Executable)
- SwiftListCLI
- SwiftListCore
Location: Purpose:
Sources/SwiftList/main.swiftThe minimal entry point that launches the CLI application:- Single responsibility: bootstrap the application
- Depends only on SwiftListCLI
- Keeps the executable target simple and focused
Core Components
ListCommand
File:Sources/SwiftListCLI/ListCommand.swift
The main command that ties everything together:
- Uses Swift ArgumentParser for declarative CLI definition
- Supports 13+ command-line flags and options
- Handles multiple path arguments
- Translates CLI flags into DisplayOptions
DisplayOptions
File:Sources/SwiftListCore/Configuration/DisplayOptions.swift
Configuration struct that controls how files are displayed:
FileManagerHelper
File:Sources/SwiftListCore/Utilities/FileManagerHelper.swift
The workhorse class that handles all file system operations:
Key Methods:
| Method | Purpose |
|---|---|
contents(with:currentDepth:) | Main entry point - lists directory contents |
fileAttributes(at:with:) | Retrieves and formats file attributes |
determineType(of:attributes:) | Determines file type (directory, symlink, executable, file) |
terminalWidth() | Gets terminal width for formatting |
- Handles symbolic links correctly (uses
lstat) - Supports recursive directory traversal with depth limiting
- Intelligent terminal width wrapping
- Platform-specific file attribute handling (Darwin/Glibc)
- Sorts files by name, size, or modification time
FileRepresentation
File:Sources/SwiftListCore/Models/FileRepresentation.swift
Model for file visual representation:
- π Directories (blue)
- π Regular files (white)
- π Symbolic links (yellow) - shows destination
- βοΈ Executable files (red)
SortOption
File:Sources/SwiftListCore/Configuration/SortOption.swift
Enum defining sort methods:
TerminalColors
File:Sources/SwiftListCore/Utilities/TerminalColors.swift
Provides ANSI color codes for terminal output:
- Blue for directories
- Yellow for symbolic links
- Red for executables
- White for regular files
- Reset code to clear formatting
Data Flow
File System Query
FileManagerHelper.contents() is called with options:- Lists directory contents
- Gets file attributes for each item
- Determines file type (icon & color)
- Sorts according to sortBy option
Formatting
Files are formatted based on display options:
- Long format: permissions, owner, size, date
- Icons: file type emoji
- Colors: ANSI escape codes
- Wrapping: terminal width calculation
Design Patterns
Separation of Concerns
CLI Layer
SwiftListCLI handles user interaction
- Argument parsing
- Command definitions
- User-facing error messages
Business Logic
SwiftListCore handles implementation
- File system operations
- Sorting and filtering
- Formatting logic
- Core library can be reused in other projects
- Easy to test business logic independently
- Clear boundaries between layers
Configuration Object
DisplayOptions acts as a configuration object passed through the system:
- Immutable options (struct semantics)
- Single source of truth for display behavior
- Easy to extend with new options
- Testable configurations
Platform Abstraction
Platform-specific code is isolated:Testing Architecture
Location:Tests/SwiftListTests.swift
Test suite using the modern Swift Testing framework:
- Tests both SwiftListCore and SwiftListCLI modules
- Uses
swift-testing(0.11.0+) for modern test syntax - Validates file operations and formatting logic
The project uses Swift Testing instead of XCTest for a more modern testing experience with better ergonomics.
External Dependencies
swift-argument-parser (1.0.0+)
swift-argument-parser (1.0.0+)
Purpose: Command-line argument parsingUsed by:
- SwiftListCLI (ListCommand definition)
- SwiftListCore (SortOption enum)
@Flag,@Option,@Argumentproperty wrappersParsableCommandprotocolCommandConfigurationfor metadata- Automatic help generation
swift-docc-plugin (1.4.3+)
swift-docc-plugin (1.4.3+)
Purpose: Documentation generationEnables:
swift package generate-documentationcommand- API documentation from doc comments
- Interactive documentation browsing
swift-testing (0.11.0+)
swift-testing (0.11.0+)
Purpose: Modern testing frameworkUsed in:
- SwiftListTests target
- Modern Swift syntax
- Better error messages
- Improved test organization
Code Organization Best Practices
The project follows Swift best practices:- Modular design - Clear module boundaries
- Protocol-oriented - Uses Swift protocols (ParsableCommand)
- Value types - Structs for DisplayOptions, FileRepresentation
- Documentation - Comprehensive doc comments
- Type safety - Enums for SortOption
- Cross-platform - Conditional compilation for Darwin/Glibc
Next Steps
Building
Learn how to build the project
Contributing
Start contributing to List