pub fn cmd_edit(beans_dir: &Path, id: &str) -> Result<()>Expand description
Orchestrate the complete bn edit workflow for a bean.
The full edit workflow:
- Validate the bean ID format
- Find the bean file using discovery
- Load the current bean content as a backup
- Open the file in the user’s configured editor
- Load the edited content
- Validate and save with schema validation (updates timestamp)
- Rebuild the index to reflect changes
If validation fails, prompts user to retry, rollback, or abort. If editor subprocess fails, handles the error gracefully.
§Arguments
beans_dir- Path to the .beans directoryid- Bean ID to edit (e.g., “1”, “1.1”)
§Returns
- Ok(()) if edit is successful and saved
- Err if:
- Bean ID not found
- $EDITOR not set or editor not found
- Editor exits with non-zero status
- Validation fails and user chooses abort
- I/O or index rebuild fails
§Examples
ⓘ
cmd_edit(Path::new(".beans"), "1")?;