Skip to main content

cqlite_cli/repl/
mod.rs

1// Core REPL Engine Module
2//
3// This module provides the core REPL (Read-Eval-Print Loop) engine for CQLite.
4// It handles command parsing, routing, execution, and provides a clean interface
5// for both the basic CLI and enhanced TUI modes.
6
7// Allow dead code during REPL development as many features are not yet fully utilized
8#![allow(dead_code)]
9
10pub mod command_parser;
11pub mod commands;
12pub mod completion;
13pub mod engine;
14pub mod history;
15pub mod session;
16
17// Re-export main interfaces
18pub use command_parser::{CommandParser, CommandType, ParsedCommand, SchemaOperation};
19pub use completion::CompletionEngine;
20pub use engine::{ReplConfig, ReplEngine};
21pub use history::HistoryManager;
22pub use session::{ReplSession, SessionState};
23
24/// Core REPL result type
25pub type ReplResult<T> = Result<T, ReplError>;
26
27/// REPL-specific error types
28#[derive(Debug, thiserror::Error)]
29pub enum ReplError {
30    #[error("IO error: {0}")]
31    Io(#[from] std::io::Error),
32
33    #[error("Database error: {0}")]
34    Database(#[from] anyhow::Error),
35
36    #[error("Command parsing error: {0}")]
37    CommandParsing(String),
38
39    #[error("Invalid configuration: {0}")]
40    Config(String),
41
42    #[error("Session error: {0}")]
43    Session(String),
44
45    #[error("History error: {0}")]
46    History(String),
47
48    #[error("Completion error: {0}")]
49    Completion(String),
50
51    // Exit code 3: Schema errors
52    #[error("Schema error: {0}")]
53    SchemaError(String),
54
55    // Exit code 4: Data directory/discovery errors
56    #[error("Data directory error: {0}")]
57    DataDirectoryError(String),
58
59    // Exit code 5: Unsupported feature
60    #[error("Unsupported feature: {0}")]
61    UnsupportedFeature(String),
62}
63
64impl ReplError {
65    /// Get the exit code for this error
66    pub fn exit_code(&self) -> i32 {
67        match self {
68            ReplError::SchemaError(_) => 3,
69            ReplError::DataDirectoryError(_) => 4,
70            ReplError::UnsupportedFeature(_) => 5,
71            _ => 1, // Generic error
72        }
73    }
74}
75
76/// Execute result indicating whether REPL should continue
77#[derive(Debug, Clone, PartialEq)]
78pub enum ExecutionResult {
79    /// Continue REPL execution
80    Continue,
81    /// Exit REPL gracefully
82    Exit,
83    /// Exit with specific code
84    ExitWithCode(i32),
85}
86
87/// REPL mode configuration
88#[derive(Debug, Clone, PartialEq)]
89pub enum ReplMode {
90    /// Basic command-line REPL
91    Basic,
92    /// Enhanced TUI mode
93    Tui,
94    /// Interactive mode with advanced features
95    Interactive,
96}
97
98/// Output format for query results
99#[derive(Debug, Clone, PartialEq)]
100pub enum OutputFormat {
101    /// Table format with borders
102    Table,
103    /// CSV format
104    Csv,
105    /// JSON format
106    Json,
107    /// Raw format (minimal)
108    Raw,
109}
110
111/// REPL command line completion context
112#[derive(Debug, Clone)]
113pub struct CompletionContext {
114    /// Current input line
115    pub line: String,
116    /// Cursor position
117    pub pos: usize,
118    /// Current session state
119    pub session_state: SessionState,
120    /// Available tables
121    pub tables: Vec<String>,
122    /// Available keyspaces
123    pub keyspaces: Vec<String>,
124}