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
4// `.concinnity/worlds/` location first, then fall back to `world.jsonl` in
5// cwd. When the fallback is hit and the target is a 3D scene (.glb),
6// `add_to_path` scaffolds a fresh 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 `.concinnity/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(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}