(args: &[String], cwd: &Path)
| 545 | } |
| 546 | |
| 547 | pub(crate) fn new_animation_command(args: &[String], cwd: &Path) -> Result<(), String> { |
| 548 | let Some(raw_name) = parse_flag_value(args, "--name") else { |
| 549 | return Err("missing required flag `--name`".to_string()); |
| 550 | }; |
| 551 | let file_name = sanitize_animation_file_name(&raw_name)?; |
| 552 | |
| 553 | let project_dir = if let Some(raw_project) = parse_flag_value(args, "--path") { |
| 554 | resolve_local_path(&raw_project, cwd) |
| 555 | } else { |
| 556 | find_project_root(cwd).ok_or_else(|| { |
| 557 | "could not find project.toml. Run from a project directory or pass --path <project_dir>." |
| 558 | .to_string() |
| 559 | })? |
| 560 | }; |
| 561 | let project_dir = project_dir.canonicalize().unwrap_or(project_dir); |
| 562 | let content_root = resolve_content_root(&project_dir, args)?; |
| 563 | let content_prefix = resolve_content_prefix(args)?; |
| 564 | |
| 565 | let target_dir = if let Some(raw_path) = parse_flag_value(args, "--res") { |
| 566 | resolve_res_subdir(&raw_path, &content_root, &content_prefix)? |
| 567 | } else { |
| 568 | content_root.join("animations") |
| 569 | }; |
| 570 | |
| 571 | let target_path = target_dir.join(file_name); |
| 572 | let animation_name = target_path |
| 573 | .file_stem() |
| 574 | .and_then(|s| s.to_str()) |
| 575 | .unwrap_or("NewAnimation"); |
| 576 | write_new_file(&target_path, &default_animation_panim(animation_name))?; |
| 577 | println!( |
| 578 | "created animation at {}", |
| 579 | normalize_powershell_path(&target_path) |
| 580 | ); |
| 581 | maybe_open_file_in_editor(args, &target_path)?; |
| 582 | Ok(()) |
| 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 { |
no test coverage detected