37 行
1.1 KiB
Rust
37 行
1.1 KiB
Rust
|
|
use std::time::Duration;
|
||
|
|
|
||
|
|
use clap::Parser;
|
||
|
|
use mock_gateway::{MockGatewayConfig, MockInstanceKind, MockScenario, spawn_mock_gateway};
|
||
|
|
|
||
|
|
#[derive(Debug, Parser)]
|
||
|
|
#[command(name = "mock-gateway")]
|
||
|
|
#[command(about = "Loopback-only deterministic AstrBot Desktop Gateway mock")]
|
||
|
|
struct Args {
|
||
|
|
#[arg(long, value_enum)]
|
||
|
|
instance: MockInstanceKind,
|
||
|
|
#[arg(long)]
|
||
|
|
port: u16,
|
||
|
|
#[arg(long, value_enum, default_value = "steady")]
|
||
|
|
scenario: MockScenario,
|
||
|
|
#[arg(long, default_value_t = 1_000)]
|
||
|
|
heartbeat_ms: u64,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[tokio::main]
|
||
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||
|
|
let args = Args::parse();
|
||
|
|
let mut config = MockGatewayConfig::new(args.instance, args.port);
|
||
|
|
config.scenario = args.scenario;
|
||
|
|
config.heartbeat_interval = Some(Duration::from_millis(args.heartbeat_ms.max(1)));
|
||
|
|
|
||
|
|
let gateway = spawn_mock_gateway(config).await?;
|
||
|
|
println!(
|
||
|
|
"{} listening at {}",
|
||
|
|
gateway.server_instance_id(),
|
||
|
|
gateway.base_url()
|
||
|
|
);
|
||
|
|
tokio::signal::ctrl_c().await?;
|
||
|
|
gateway.shutdown().await?;
|
||
|
|
Ok(())
|
||
|
|
}
|