MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / handle_gql

Function handle_gql

gql-cli/src/cli/gqlcli.rs:116–258  ·  view source on GitHub ↗

Handle the gql (REPL) command

(
    path: PathBuf,
    user: Option<String>,
    password: Option<String>,
    _sample: bool,
)

Source from the content-addressed store, hash-verified

114
115/// Handle the gql (REPL) command
116pub fn handle_gql(
117 path: PathBuf,
118 user: Option<String>,
119 password: Option<String>,
120 _sample: bool,
121) -> Result<(), Box<dyn std::error::Error>> {
122 // Check if database exists
123 if !path.exists() {
124 return Err(format!(
125 "Database not found at {:?}. Run 'cargo run -- install' first.",
126 path
127 )
128 .into());
129 }
130
131 // Prompt for credentials if not provided
132 let username = user.unwrap_or_else(|| {
133 print!("Username: ");
134 std::io::Write::flush(&mut std::io::stdout()).unwrap();
135 let mut input = String::new();
136 std::io::stdin().read_line(&mut input).unwrap();
137 input.trim().to_string()
138 });
139
140 let password = password.unwrap_or_else(|| {
141 print!("Password: ");
142 std::io::Write::flush(&mut std::io::stdout()).unwrap();
143 rpassword::read_password().unwrap()
144 });
145
146 // Load database
147 let coordinator = load_database(&path)?;
148
149 // Authenticate
150 let session_id = authenticate(&coordinator, &username, &password)?;
151
152 println!("{}", "GraphLite".bold().green());
153 println!("Type 'help' for commands, 'exit' or 'quit' to exit");
154 println!("Multi-line queries supported - use ';' to terminate\n");
155 println!("{}", format!("Authenticated as: {}", username).cyan());
156 println!("Session ID: {}", session_id);
157
158 // Create REPL editor
159 let config = Config::builder()
160 .edit_mode(EditMode::Emacs)
161 .history_ignore_space(true)
162 .completion_type(CompletionType::List)
163 .auto_add_history(false)
164 .build();
165
166 let mut rl = Editor::<(), _>::with_config(config)?;
167
168 let history_path = ".graphlite/.gql_history.txt";
169 if let Some(parent) = Path::new(&history_path).parent() {
170 std::fs::create_dir_all(parent)?;
171 }
172
173 let _ = rl.load_history(&history_path);

Callers 1

mainFunction · 0.85

Calls 11

load_databaseFunction · 0.85
authenticateFunction · 0.85
print_helpFunction · 0.85
unwrapMethod · 0.80
process_queryMethod · 0.80
containsMethod · 0.80
existsMethod · 0.45
buildMethod · 0.45
is_emptyMethod · 0.45
clearMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected