Skip to main content

concinnity_dev/command/
add.rs

1// src/cli/add.rs: discovery wrapper around crate::add_to_path
2//
3// The CLI binary handles world-path discovery: try the standard `worlds/`
4// location first, then fall back to `world.jsonl` in cwd. When the fallback is
5// hit and the target is a 3D scene (.glb), `add_to_path` scaffolds a fresh
6// world at that location.
7
8use crate::add_to_path;
9use concinnity_cook::authoring::world::{WORLD_JSONL, find_world_jsonl};
10
11/// Create an asset from `target` and apply it to the discovered world.
12///
13/// Tries `worlds/` first, then `world.jsonl` in the working
14/// directory; when neither exists and the target is a 3D scene, the world is
15/// scaffolded at the fallback location.
16pub fn add(name: Option<&str>, target: &str, template: Option<&str>) -> std::io::Result<()> {
17    let world_path = match find_world_jsonl(crate::project::worlds_dir().as_deref(), None) {
18        Ok(p) => p,
19        Err(e) if e.kind() == std::io::ErrorKind::NotFound => WORLD_JSONL.to_string(),
20        Err(e) => return Err(e),
21    };
22    add_to_path(&world_path, name, target, template)
23}