Skip to main content

find_unit_file

Function find_unit_file 

Source
pub fn find_unit_file(mana_dir: &Path, id: &str) -> Result<PathBuf, Error>
Expand description

Find a unit file by ID, supporting both new and legacy naming conventions.

Searches for unit files in this order:

  1. New format: {id}-{slug}.md (e.g., “1-my-task.md”, “11.1-refactor-parser.md”)
  2. Legacy format: {id}.yaml (e.g., “1.yaml”, “11.1.yaml”)

Returns the full path if found.

§Examples

  • find_unit_file(mana_dir, "1").mana/1-my-task.md or .mana/1.yaml
  • find_unit_file(mana_dir, "11.1").mana/11.1-refactor-parser.md or .mana/11.1.yaml

§Arguments

  • mana_dir - Path to the .mana/ directory
  • id - The unit ID to find (e.g., “1”, “11.1”, “3.2.1”)

§Errors

  • If the ID is invalid (empty, contains path traversal, etc.)
  • If no unit file is found for the given ID
  • If glob pattern matching fails