DOCUMENTATION / V1.0.0 LTS
Console.rs Extraction - Quick Start Guide
Location:
/home/ldjiba/Sources/repos/OrbitOne/src/console.rs
📊 What You're Extracting
From console.rs (3,700 lines) to separate command modules:
| Document | Purpose | Use For |
|---|---|---|
| CONSOLE_EXTRACTION_ANALYSIS.md | Complete technical blueprint | Understanding what to extract, exact line ranges, dependencies |
| CONSOLE_COMMANDS_REFERENCE.csv | Quick lookup table | Finding a command, its line numbers, and complexity |
| CONSOLE_DEPENDENCIES.md | Dependency matrix | Understanding what each module needs to import |
| CONSOLE_VISUAL_MAP.md | Visual organization | Understanding code structure and extraction strategy |
| This guide | Quick reference | Getting started fast |
🎯 TL;DR - What to Do
The Numbers
- 2,725 lines to extract (commands + helpers)
- 49 commands across 4 modules
- 62+ helper functions to move
- ~8.5 hours total effort estimated
The Modules
📁 commands/ (NEW)
├── mod.rs (dispatch router)
├── help.rs (3 commands, 95 lines) ← START HERE
├── storage.rs (11 commands, 250 lines)
├── system.rs (20+ commands, 1,700 lines)
└── memory.rs (7 commands, 680 lines) OR split into:
├── memory.rs (memory command only)
├── paging.rs (paging command - 378 lines!)
└── health.rs (status/health/diagnose)
🔍 Finding Command Code
Option 1: Use Line Numbers (Fastest)
Open src/console.rs and go to line number:
Help section: Lines 595-677
Storage (filesystem): Lines 1794-2125
System/monitoring: Lines 678-1026, 1515-1723, 2126-2203
Memory/paging: Lines 812-1514
Option 2: Search by Command Name
Find your command in the execute_command function:
Ctrl+F in VS Code: "if eq_ignore_ascii_case(name, b"COMMAND_NAME""
Example: Find ls command
Result: Line 1842: if eq_ignore_ascii_case(name, b"ls") {
Option 3: Use CSV Reference
Open CONSOLE_COMMANDS_REFERENCE.csv - all commands
listed with line ranges
📝 How to Extract a Command
Example: Extract
help command (Lines 595-631)
Find the dispatch block:
// Line 595 if eq_ignore_ascii_case(name, b"help") { // ... command body ... return; }Identify called functions:
- Calls:
print_help_general(),print_help_shell(), etc. - These MUST be extracted together
- Calls:
Find helper functions:
- Search for
fn print_help_general() - Copy entire function body
- Check what it calls (other functions to extract)
- Search for
Extract to help.rs:
pub fn handle_help_command(name: &[u8], args: &[u8]) { if eq_ignore_ascii_case(name, b"help") { // ... command body from console.rs ... return; } }Update dependencies:
- Import needed:
crate::serial_println! - Import helpers: move
print_help_general(), etc.
- Import needed:
🛠️ Step-by-Step Extraction Process
PHASE 1: Setup (15 minutes)
# Create directory structure
mkdir -p src/commands
# Create files with stubs
touch src/commands/mod.rs
touch src/commands/help.rs
touch src/commands/storage.rs
touch src/commands/system.rs
touch src/commands/memory.rsPHASE 2: Extract help.rs (30 minutes)
- Open
CONSOLE_EXTRACTION_ANALYSIS.md→ Search for "Help-related handlers" - Copy lines 595-677 from console.rs
- Copy helper functions (print_help_*, print_aliases)
- Paste into src/commands/help.rs
- Fix imports
PHASE 3: Extract storage.rs (1 hour)
- Open
CONSOLE_EXTRACTION_ANALYSIS.md→ Search for "Storage handlers" - Copy lines 1794-2125
- Copy helpers: resolve_shell_path, print_tree_recursive, etc.
- Paste into src/commands/storage.rs
- Add WORKING_DIR access
- Fix imports
PHASE 4: Extract system.rs (2-3 hours)
- Find all system commands in CONSOLE_EXTRACTION_ANALYSIS.md
- Copy dispatch blocks (multiple non-contiguous ranges!)
- Copy 35+ helper functions
- Organize by category in file
- Fix imports
PHASE 5: Extract memory.rs (2-3 hours)
- Copy lines 812-1514 (memory, paging, health, diagnose commands)
- Copy all helper functions
- Decision point: Keep as one file or split?
- Option A: Single memory.rs with 680 lines
- Option B: Split into memory.rs, paging.rs, health.rs
PHASE 6: Integration (1 hour)
- Create commands/mod.rs dispatcher
- Update console.rs execute_command() to call dispatcher
- Test compilation
- Test command execution
🔗 Dependencies Reference
For help.rs
// Need to import:
use crate::serial_println;
use crate::shell_parse;
// Use from console.rs:
fn ascii_bytes_to_str(bytes: &[u8]) -> &strFor storage.rs
// Need:
use alloc::string::String;
use crate::serial_println;
use crate::fs;
use crate::pathing;
// Need access to:
WORKING_DIR: Mutex<WorkingDirectoryState>
// Functions to move:
current_working_dir()
set_current_working_dir()
resolve_shell_path()
print_tree_recursive()For system.rs
// Need many crate imports:
use crate::cpu;
use crate::interrupts;
use crate::paging;
use crate::memory;
use crate::boot;
use crate::power;
use crate::serial;
use crate::server_tasks;
// Move 40+ print functions
// Access collect_health_state()For memory.rs
// Heavy dependencies:
use crate::paging;
use crate::memory;
use crate::interrupts;
use crate::cpu;
use crate::boot;
// Struct to move:
struct HealthState { ... }
// Functions to move:
collect_health_state()
print_diagnose()
print_diagnose_json()⚠️ Critical Gotchas
1. Paging Command is HUGE (378 lines)
- Consider extracting to separate paging.rs
- Has 30+ sub-commands
- Most complex in entire file
- Risk: highest
2. Shared State Access
- WORKING_DIR must be accessible by storage.rs
- CONSOLE must be readable by system.rs (history)
- Don't duplicate state - share via pub reference
3. Helper Function Reuse
These are used by MULTIPLE modules:
ascii_bytes_to_str()- move to common moduleeq_ignore_ascii_case()- delegates to shell_parseparse_usize_arg()- used by memory, system
4. Print Functions Dependencies
Many print functions call OTHER print functions:
- Example:
print_diagnose_json()calls many helpers - Must extract entire chain, not just one function
5. Compilation Issues
When compiling after extraction:
- You'll get "function not found" errors
- This means you missed extracting a helper
- Check CONSOLE_EXTRACTION_ANALYSIS.md for "Helper Functions" section
- Search console.rs for
fnfollowed by the missing function name
📋 Extraction Checklist
[ ] Setup
[ ] Phase 1: help.rs
[ ] Phase 2: storage.rs
[ ] Phase 3: system.rs
[ ] Phase 4: memory.rs
[ ] Phase 5: Integration
[ ] Phase 6: Cleanup
🚀 Start Here
- Read:
CONSOLE_VISUAL_MAP.md(5 min) - Understand structure - Reference: Keep
CONSOLE_COMMANDS_REFERENCE.csvopen in editor - Deep dive: Use
CONSOLE_EXTRACTION_ANALYSIS.mdfor detailed line ranges - Check dependencies: Use
CONSOLE_DEPENDENCIES.mdbefore extracting each module - Start small: Begin with help.rs (lowest complexity)
📞 Troubleshooting
| Problem | Solution |
|---|---|
| "Function not found" error | Function wasn't extracted. Search CONSOLE_EXTRACTION_ANALYSIS.md for function name in "Helper Functions" section |
| Multiple line ranges needed | Some commands are in different parts of file. See CONSOLE_VISUAL_MAP.md for complete ranges |
| Compilation fails | Missing imports. Check CONSOLE_DEPENDENCIES.md for required crates |
| Can't find WORKING_DIR | It's in console.rs around line 150. You need pub access or pass as parameter |
| Memory.rs too large | Consider splitting: memory.rs + paging.rs + health.rs (recommended) |
🎯 Success Criteria
After extraction, you should have:
✅ src/commands/mod.rs - dispatcher ✅
src/commands/help.rs - 3 commands, 95 lines ✅
src/commands/storage.rs - 11 commands, 250 lines ✅
src/commands/system.rs - 20+ commands, 1,700 lines ✅
src/commands/memory.rs - 7 commands, 680 lines (or split)
✅ src/console.rs - reduced to ~500 lines ✅ All
commands still work identically ✅ Code compiles
without warnings ✅ Tests pass
Ready to start? Begin with help.rs - it's the simplest!