From 10eae9b36cfe82b86fe0bf4d7c02f99d727b839d Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sat, 26 Aug 2023 19:31:54 +0200 Subject: [PATCH] feat: with extra churning repl thingy Signed-off-by: kjuulh --- crates/churn/src/main.rs | 4 +-- crates/churning/src/main.rs | 64 +++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/crates/churn/src/main.rs b/crates/churn/src/main.rs index 89ac740..9e67468 100644 --- a/crates/churn/src/main.rs +++ b/crates/churn/src/main.rs @@ -13,7 +13,7 @@ struct Command { enum Commands { Bootstrap { #[arg(env = "CHURN_AGENT", long)] - host: String, + agent: String, #[arg(env = "CHURN_SERVER", long)] server: String, @@ -45,7 +45,7 @@ async fn handle_command(cmd: Command) -> anyhow::Result<()> { if let Some(cmd) = cmd.command { match cmd { Commands::Bootstrap { - host, + agent, server, server_token, } => todo!(), diff --git a/crates/churning/src/main.rs b/crates/churning/src/main.rs index 6e7ea91..5087b20 100644 --- a/crates/churning/src/main.rs +++ b/crates/churning/src/main.rs @@ -1,11 +1,17 @@ use std::{path::PathBuf, sync::Arc}; use dagger_rust::build::{RustVersion, SlimImage}; -use dagger_sdk::Query; +use dagger_sdk::{Config, Query}; +use tokio::io::{AsyncBufReadExt, AsyncWriteExt}; #[tokio::main] async fn main() -> eyre::Result<()> { - let client = dagger_sdk::connect().await?; + let mut config = Config::default(); + config.logger = None; + + println!("Building churning..."); + + let client = dagger_sdk::connect_opts(config).await?; let agent = build_container(client.clone(), "churn-agent").await?; let agent = agent @@ -35,6 +41,60 @@ async fn main() -> eyre::Result<()> { println!("{stderr}"); churning.exit_code().await?; + println!("Finished building churning..."); + + repl(churning).await?; //.with_entrypoint(vec!["churn"])).await?; + + Ok(()) +} + +async fn repl(container: dagger_sdk::Container) -> eyre::Result<()> { + let mut container = container; + + loop { + let mut stdin = tokio::io::stdin(); + let mut stdout = tokio::io::stdout(); + + stdout.write_all(b"> ").await?; + stdout.flush().await?; + + let mut input = String::new(); + + let mut stdin = tokio::io::BufReader::new(stdin); + + stdin.read_line(&mut input).await?; + + let input = input.trim(); + if input == "q" { + break; + } + + container = container.with_exec(input.split(' ').collect()); + + match container.stdout().await { + Ok(stdout) => { + println!("{stdout}"); + } + Err(e) => { + eprintln!("{}", e); + } + } + match container.stderr().await { + Ok(stderr) => { + println!("{stderr}"); + } + Err(e) => { + eprintln!("{}", e); + } + } + + match container.exit_code().await { + Ok(_) => {} + Err(_e) => { + //eprintln!("encountred error: {}", e); + } + } + } Ok(()) }