refactor(simulation): split atlas.rs subcommands into modules
Extract 2119-line monolithic atlas.rs into 8 focused modules under src/bin/atlas/: main.rs (thin dispatch), common.rs (shared types and DB helpers), show.rs, mutate.rs, stats.rs, systems.rs, author.rs, and sync_wiki.rs. Commands enum stays in main.rs; each match arm delegates to module::cmd_fn(&conn, args). No behavior change. Closes #776. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
use std::process;
|
||||
|
||||
use rusqlite::{params, Connection};
|
||||
use serde::Serialize;
|
||||
|
||||
pub fn cmd_add_body(
|
||||
conn: &Connection,
|
||||
id: &str,
|
||||
system: &str,
|
||||
r#type: &str,
|
||||
orbit: Option<i32>,
|
||||
name: &Option<String>,
|
||||
parent: &Option<String>,
|
||||
mass_class: &Option<String>,
|
||||
atmosphere: &Option<String>,
|
||||
gravity: Option<f64>,
|
||||
biome: &Option<String>,
|
||||
inhabited: bool,
|
||||
population: Option<i64>,
|
||||
) {
|
||||
conn.execute(
|
||||
"INSERT INTO bodies (body_id, system_id, parent_body_id, body_type, orbit_index,
|
||||
proper_name, mass_class, atmosphere, surface_gravity,
|
||||
biome_summary, inhabited, population)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)",
|
||||
params![
|
||||
id,
|
||||
system,
|
||||
parent,
|
||||
r#type,
|
||||
orbit,
|
||||
name,
|
||||
mass_class,
|
||||
atmosphere,
|
||||
gravity,
|
||||
biome,
|
||||
inhabited as i32,
|
||||
population.unwrap_or(0),
|
||||
],
|
||||
)
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("error: {}", e);
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
println!(r#"{{"ok": true, "body_id": "{}"}}"#, id);
|
||||
}
|
||||
|
||||
pub fn cmd_add_station(
|
||||
conn: &Connection,
|
||||
id: &str,
|
||||
system: &str,
|
||||
orbits: &Option<String>,
|
||||
r#type: &str,
|
||||
name: &Option<String>,
|
||||
population: Option<i64>,
|
||||
docking: &Option<String>,
|
||||
gate: bool,
|
||||
) {
|
||||
conn.execute(
|
||||
"INSERT INTO stations (station_id, system_id, orbits_body_id, station_type,
|
||||
proper_name, population, docking_class, has_gate_infrastructure)
|
||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",
|
||||
params![
|
||||
id,
|
||||
system,
|
||||
orbits,
|
||||
r#type,
|
||||
name,
|
||||
population.unwrap_or(0),
|
||||
docking,
|
||||
gate as i32,
|
||||
],
|
||||
)
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("error: {}", e);
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
println!(r#"{{"ok": true, "station_id": "{}"}}"#, id);
|
||||
}
|
||||
|
||||
pub fn cmd_wipe_system(conn: &Connection, system_id: &str) {
|
||||
let stations_deleted: usize = conn
|
||||
.execute(
|
||||
"DELETE FROM stations WHERE system_id = ?1",
|
||||
params![system_id],
|
||||
)
|
||||
.unwrap();
|
||||
let bodies_deleted: usize = conn
|
||||
.execute(
|
||||
"DELETE FROM bodies WHERE system_id = ?1",
|
||||
params![system_id],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct WipeResult {
|
||||
system_id: String,
|
||||
bodies_deleted: usize,
|
||||
stations_deleted: usize,
|
||||
}
|
||||
let result = WipeResult {
|
||||
system_id: system_id.to_string(),
|
||||
bodies_deleted,
|
||||
stations_deleted,
|
||||
};
|
||||
println!("{}", serde_json::to_string_pretty(&result).unwrap());
|
||||
}
|
||||
Reference in New Issue
Block a user