feat: add agent
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-11-24 00:53:43 +01:00
parent 7487e7336e
commit d1e9eb9eb5
8 changed files with 418 additions and 11 deletions

View File

@@ -2,19 +2,28 @@ use std::net::SocketAddr;
use clap::{Parser, Subcommand};
use crate::{api, state::SharedState};
use crate::{agent, api, state::SharedState};
pub async fn execute() -> anyhow::Result<()> {
let state = SharedState::new().await?;
let cli = Command::parse();
if let Some(Commands::Serve { host }) = cli.command {
tracing::info!("Starting service");
match cli.command.expect("to have a subcommand") {
Commands::Serve { host } => {
tracing::info!("Starting service");
notmad::Mad::builder()
.add(api::Api::new(&state, host))
.run()
.await?;
notmad::Mad::builder()
.add(api::Api::new(&state, host))
.run()
.await?;
}
Commands::Agent { commands } => match commands {
AgentCommands::Start { host } => {
tracing::info!("starting agent");
agent::execute(host).await?;
tracing::info!("shut down agent");
}
},
}
Ok(())
@@ -33,4 +42,16 @@ enum Commands {
#[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")]
host: SocketAddr,
},
Agent {
#[command(subcommand)]
commands: AgentCommands,
},
}
#[derive(Subcommand)]
enum AgentCommands {
Start {
#[arg(env = "SERVICE_HOST", long = "service-host")]
host: String,
},
}