(arguments: Arguments)
| 60 | } |
| 61 | |
| 62 | fn launch_fileql_repl(arguments: Arguments) { |
| 63 | let mut reporter = diagnostic_reporter::DiagnosticReporter::default(); |
| 64 | let files = &arguments.files; |
| 65 | if let Err(error) = validate_files_paths(files) { |
| 66 | reporter.report_diagnostic("", Diagnostic::error(error.as_str())); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | let mut global_env = create_fileql_environment(); |
| 71 | |
| 72 | let mut input = String::new(); |
| 73 | |
| 74 | loop { |
| 75 | let stdio = io::stdin(); |
| 76 | |
| 77 | // Render Prompt only if input is received from terminal |
| 78 | if stdio.is_terminal() { |
| 79 | print!("fileql > "); |
| 80 | } |
| 81 | |
| 82 | std::io::Write::flush(&mut std::io::stdout()).expect("flush failed!"); |
| 83 | match stdio.read_line(&mut input) { |
| 84 | Ok(buffer_length) => { |
| 85 | if buffer_length == 0 { |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | Err(error) => { |
| 90 | reporter.report_diagnostic(&input, Diagnostic::error(&format!("{}", error))); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | let stdin_input = input.trim(); |
| 95 | if stdin_input.is_empty() || stdin_input == "\n" { |
| 96 | continue; |
| 97 | } |
| 98 | |
| 99 | if stdin_input == "exit" { |
| 100 | println!("Goodbye!"); |
| 101 | break; |
| 102 | } |
| 103 | |
| 104 | execute_fileql_query( |
| 105 | stdin_input.to_owned(), |
| 106 | &arguments, |
| 107 | files, |
| 108 | &mut global_env, |
| 109 | &mut reporter, |
| 110 | ); |
| 111 | |
| 112 | input.clear(); |
| 113 | global_env.clear_session(); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | fn execute_fileql_query( |
| 118 | query: String, |
no test coverage detected