feat: add labels to config
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::net::SocketAddr;
|
||||
use std::{collections::BTreeMap, net::SocketAddr};
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
@@ -21,8 +21,17 @@ pub async fn execute() -> anyhow::Result<()> {
|
||||
agent::execute().await?;
|
||||
tracing::info!("shut down agent");
|
||||
}
|
||||
AgentCommands::Setup { force, discovery } => {
|
||||
agent::setup_config(discovery, force).await?;
|
||||
AgentCommands::Setup {
|
||||
force,
|
||||
discovery,
|
||||
labels,
|
||||
} => {
|
||||
let mut setup_labels = BTreeMap::new();
|
||||
for (k, v) in labels {
|
||||
setup_labels.insert(k, v);
|
||||
}
|
||||
|
||||
agent::setup_config(discovery, force, setup_labels).await?;
|
||||
tracing::info!("wrote default agent config");
|
||||
}
|
||||
},
|
||||
@@ -65,5 +74,15 @@ enum AgentCommands {
|
||||
|
||||
#[arg(env = "DISCOVERY_HOST", long = "discovery")]
|
||||
discovery: String,
|
||||
|
||||
#[arg(long = "label", short = 'l', value_parser = parse_key_val, action = clap::ArgAction::Append)]
|
||||
labels: Vec<(String, String)>,
|
||||
},
|
||||
}
|
||||
|
||||
fn parse_key_val(s: &str) -> Result<(String, String), String> {
|
||||
let (key, value) = s
|
||||
.split_once("=")
|
||||
.ok_or_else(|| format!("invalid key=value: no `=` found in `{s}`"))?;
|
||||
Ok((key.to_string(), value.to_string()))
|
||||
}
|
||||
|
Reference in New Issue
Block a user