(args: &[String], cwd: &Path)
| 583 | } |
| 584 | |
| 585 | pub(crate) fn new_panimtree_command(args: &[String], cwd: &Path) -> Result<(), String> { |
| 586 | let Some(raw_name) = parse_flag_value(args, "--name") else { |
| 587 | return Err("missing required flag `--name`".to_string()); |
| 588 | }; |
| 589 | let file_name = sanitize_panimtree_file_name(&raw_name)?; |
| 590 | |
| 591 | let project_dir = if let Some(raw_project) = parse_flag_value(args, "--path") { |
| 592 | resolve_local_path(&raw_project, cwd) |
| 593 | } else { |
| 594 | find_project_root(cwd).ok_or_else(|| { |
| 595 | "could not find project.toml. Run from a project directory or pass --path <project_dir>." |
| 596 | .to_string() |
| 597 | })? |
| 598 | }; |
| 599 | let project_dir = project_dir.canonicalize().unwrap_or(project_dir); |
| 600 | let content_root = resolve_content_root(&project_dir, args)?; |
| 601 | let content_prefix = resolve_content_prefix(args)?; |
| 602 | |
| 603 | let target_dir = if let Some(raw_path) = parse_flag_value(args, "--res") { |
| 604 | resolve_res_subdir(&raw_path, &content_root, &content_prefix)? |
| 605 | } else { |
| 606 | content_root.join("animations") |
| 607 | }; |
| 608 | |
| 609 | let target_path = target_dir.join(file_name); |
| 610 | let tree_name = target_path |
| 611 | .file_stem() |
| 612 | .and_then(|s| s.to_str()) |
| 613 | .unwrap_or("NewAnimationTree"); |
| 614 | write_new_file(&target_path, &default_panimtree(tree_name))?; |
| 615 | println!( |
| 616 | "created animation tree at {}", |
| 617 | normalize_powershell_path(&target_path) |
| 618 | ); |
| 619 | maybe_open_file_in_editor(args, &target_path)?; |
| 620 | Ok(()) |
| 621 | } |
no test coverage detected