feat: with extra churning repl thingy

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-08-26 19:31:54 +02:00
parent 8c41e1004c
commit 10eae9b36c
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
2 changed files with 64 additions and 4 deletions

View File

@ -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!(),

View File

@ -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(())
}