This commit is contained in:
lda
2026-04-13 00:33:49 +07:00 Unverified
parent 8fdfc288b4
commit 1bbbe1615e
6 changed files with 64 additions and 37 deletions
+7 -3
View File
@@ -64,9 +64,13 @@ pub struct EnrollArgs {
#[derive(Args)]
pub struct InitConfigArgs {
/// Path to the agent config file to write.
#[arg(long, default_value = config::DEFAULT_CONFIG_PATH)]
pub config: PathBuf,
/// Path to the agent config file to write. If omitted, config is printed to stdout.
#[arg(long)]
pub config: Option<PathBuf>,
/// Print config to stdout.
#[arg(long, conflicts_with = "config")]
pub stdout: bool,
/// Base HTTPS URL of the control plane.
#[arg(long)]
+19 -9
View File
@@ -36,7 +36,6 @@ async fn main() -> Result<()> {
}
}
Command::InitConfig(args) => {
::tracing::info!(config = %args.config.display(), force = args.force, "wakey-agent command: init-config");
init_config(args)?
}
Command::Reload(args) => {
@@ -49,11 +48,17 @@ async fn main() -> Result<()> {
}
fn init_config(args: InitConfigArgs) -> Result<()> {
if args.config.exists() && !args.force {
anyhow::bail!(
"config {} already exists; re-run with --force to overwrite",
args.config.display()
);
if args.stdout && args.config.is_some() {
anyhow::bail!("--stdout cannot be used with --config");
}
if let Some(config) = &args.config {
if config.exists() && !args.force {
anyhow::bail!(
"config {} already exists; re-run with --force to overwrite",
config.display()
);
}
}
let cfg = config::AgentConfig {
@@ -70,8 +75,13 @@ fn init_config(args: InitConfigArgs) -> Result<()> {
reconnect_max_ms: 30_000,
};
config::save_config(&args.config, &cfg)?;
println!("config={}", args.config.display());
println!("next=wakey-agent serve --config {}", args.config.display());
if let Some(path) = &args.config {
config::save_config(path, &cfg)?;
println!("config={}", path.display());
println!("next=wakey-agent serve --config {}", path.display());
} else {
let rendered = toml::to_string_pretty(&cfg)?;
print!("{}", rendered);
}
Ok(())
}