()
| 47 | |
| 48 | #[tokio::main] |
| 49 | async fn main() { |
| 50 | dotenv::dotenv().ok(); |
| 51 | Config::load("project.toml"); |
| 52 | |
| 53 | let cli = AIScriptCli::parse(); |
| 54 | match cli.command { |
| 55 | Some(Commands::Serve { file, port, reload }) => { |
| 56 | println!("Server listening on port http://localhost:{}", port); |
| 57 | aiscript_runtime::run(file, port, reload).await; |
| 58 | } |
| 59 | Some(Commands::New { name }) => { |
| 60 | let generator = ProjectGenerator::new(&name); |
| 61 | if let Err(e) = generator.generate() { |
| 62 | eprintln!("{}", e); |
| 63 | process::exit(1); |
| 64 | } |
| 65 | } |
| 66 | None => { |
| 67 | if let Some(path) = cli.file { |
| 68 | let pg_connection = aiscript_runtime::get_pg_connection().await; |
| 69 | let sqlite_connection = aiscript_runtime::get_sqlite_connection().await; |
| 70 | let redis_connection = aiscript_runtime::get_redis_connection().await; |
| 71 | task::spawn_blocking(move || { |
| 72 | let mut vm = Vm::new(pg_connection, sqlite_connection, redis_connection); |
| 73 | vm.run_file(path); |
| 74 | }) |
| 75 | .await // must use await to wait for the thread to finish |
| 76 | .unwrap(); |
| 77 | } else { |
| 78 | // Run the repl |
| 79 | let mut repl = Repl::new(); |
| 80 | if let Err(e) = repl.run() { |
| 81 | eprintln!("Error: {}", e); |
| 82 | process::exit(1); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
nothing calls this directly
no test coverage detected