use crate::cli::{ok, DEFAULT_PORT};
use anyhow::Result;
use clap::Parser;
use std::time::Duration;

#[derive(Parser)]
pub struct Args {
    #[arg(long, default_value_t = DEFAULT_PORT)]
    pub port: u16,
}

pub fn run(args: Args) -> Result<()> {
    let url = format!("http://127.0.0.1:{}/shutdown", args.port);
    let _ = ureq::post(&url)
        .timeout(Duration::from_secs(2))
        .send_string("");
    ok(format!("sent shutdown to port {}", args.port));
    Ok(())
}