Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GitHub

This documentation is part of the "Projects with Books" initiative at zenOSmosis.

The source code for this project is available on GitHub.

CLI Commands Reference

Loading…

CLI Commands Reference

Relevant source files

This page provides a comprehensive technical reference for the simd-r-drive Command Line Interface (CLI). The CLI serves as the primary entry point for interacting with the append-only storage engine, providing commands for data manipulation, maintenance, and inspection.

Architecture Overview

The CLI is built using the clap crate for argument parsing and delegates all core logic to the DataStore engine. The execution flow follows a pattern of parsing arguments into a Cli struct, which contains a Commands enum, and then dispatching these to the execute_command function src/cli/execute_command.rs:25-26

CLI Data Flow and Entity Mapping

The following diagram illustrates how CLI commands map to specific functions within the DataStore and how data streams through the system.

Diagram: CLI to Storage Engine Mapping

graph TD
    subgraph "CLI Layer (src/cli/)"
 
       A["Cli Struct (src/cli/cli_parser.rs)"] --> B["Commands Enum (src/cli/commands.rs)"]
B --> C["execute_command() (src/cli/execute_command.rs)"]
end

    subgraph "Logic & Data Flow"
        C -- "Read/Stream" --> D["EntryStream (src/storage_engine/entry_stream.rs)"]
C -- "Write/Stream" --> E["DataStoreWriter::write_stream()"]
C -- "Maintenance" --> F["DataStore::compact()"]
end

    subgraph "Core Engine (src/storage_engine/)"
 
       D --> G["DataStoreReader::read()"]
E --> H["DataStore::write_stream()"]
F --> I["EntryIterator (src/storage_engine/entry_iterator.rs)"]
end

    style A stroke-dasharray: 5 5
    style G font-weight:bold
    style H font-weight:bold

Sources: src/cli/execute_command.rs:1-7 src/cli/execute_command.rs:25-174 src/cli/commands.rs:5-65


Command Reference

Read

Retrieves the value associated with a specific key and outputs it to stdout.

Sources: src/cli/commands.rs:7-14 src/cli/execute_command.rs:27-85 tests/cli_tests.rs:111-167

Write

Stores a value for a given key. Supports both direct arguments and piped input.

  • Usage: <storage> write <key> [value]
  • Direct Write: If value is provided as an argument, it is written directly to the store using DataStore::write() src/cli/execute_command.rs:91-95
  • Piped Stdin: If value is omitted and stdin is not a terminal, the CLI uses DataStore::write_stream() to pipe data from stdin directly into the storage file src/cli/execute_command.rs:96-103
  • Validation: If neither a value nor a pipe is detected (checked via is_terminal() and the FORCE_NO_TTY environment variable), the command exits with an error src/cli/execute_command.rs:96-108

Sources: src/cli/commands.rs:17-23 src/cli/execute_command.rs:87-111 tests/cli_tests.rs:45-67

Copy, Move, and Rename

These commands manage entry lifecycle across the same or different storage files.

CommandActionImplementation
copyCopies a key’s latest entry to a target storage file.source_storage.copy(key, &target_storage) src/cli/execute_command.rs:119-120
moveCopies the entry to a target file and deletes it from the source.source_storage.transfer(key, &target_storage) src/cli/execute_command.rs:136-137
renameChanges the key associated with an entry within the same file.storage.rename(old_key, new_key) src/cli/execute_command.rs:151-152

Sources: src/cli/commands.rs:26-46 src/cli/execute_command.rs:113-160

Delete

Marks a key as deleted by appending a “tombstone” entry to the storage file.

  • Usage: <storage> delete <key>
  • Implementation: Calls DataStore::delete(), which ensures the key is no longer reachable via the index by writing a null-payload entry src/cli/execute_command.rs:165-167

Sources: src/cli/commands.rs:49-52 src/cli/execute_command.rs:162-169

Compact

Reclaims disk space by removing shadowed (old) versions of keys and deleted entries.

Sources: src/cli/commands.rs55 src/cli/execute_command.rs:171-174

Info and Metadata

Provides diagnostic information about the storage file or a specific entry.

Sources: src/cli/commands.rs:58-64 src/cli/execute_command.rs26


Execution Logic and Error Handling

The CLI uses a centralized execute_command function to handle the lifecycle of a command, from opening the DataStore to handling I/O errors.

Diagram: Write Command Execution Flow

sequenceDiagram
    participant U as "User/Shell"
    participant C as "execute_command (src/cli/execute_command.rs)"
    participant S as "DataStore (src/storage_engine/mod.rs)"
    participant F as "File System"

    U->>C: write key [value]
    alt "Value Provided"
        C->>S: DataStore::write(key, value)
        S->>F: Append Entry
    else "Piped Stdin"
        U->>C: "echo 'data' | bin write key"
        C->>S: DataStore::write_stream(key, stdin)
        loop "Chunked Read"
            S->>F: Append Chunks via SIMD/Scalar
        end
    end
    C->>U: Print 'Stored key'

Key Functions

Sources: src/cli/execute_command.rs:25-174 src/utils/mod.rs:1-10


Global Options

Storage Path

The first argument to the binary is always the path to the storage file. If the file does not exist, commands like write will create it automatically via DataStore::open, while read will fail via DataStore::open_existing src/cli/execute_command.rs28 src/cli/execute_command.rs88

Buffer Size Flag

Available on the read command, the --buffer-size (or -b) flag controls the internal memory allocation for streaming data from the storage engine to stdout. This is particularly useful when reading very large entries to prevent excessive memory consumption src/cli/commands.rs:11-13

Sources: src/cli/commands.rs:7-14 tests/cli_tests.rs:111-167