| 837 | } |
| 838 | |
| 839 | fn load_lifecycle(dir: &Path, run_id: &str) -> CliResult<Option<ManagedLifecycle>> { |
| 840 | validate_run_id(run_id)?; |
| 841 | let path = lifecycle_path(dir, run_id); |
| 842 | if !path.exists() { |
| 843 | return Ok(None); |
| 844 | } |
| 845 | let data = fs::read_to_string(&path).map_err(|e| { |
| 846 | CliError::Internal(anyhow!( |
| 847 | "failed to read managed lifecycle '{}': {}", |
| 848 | path.display(), |
| 849 | e |
| 850 | )) |
| 851 | })?; |
| 852 | let mut lifecycle: ManagedLifecycle = serde_json::from_str(&data).map_err(|e| { |
| 853 | CliError::Internal(anyhow!( |
| 854 | "failed to parse managed lifecycle '{}': {}", |
| 855 | path.display(), |
| 856 | e |
| 857 | )) |
| 858 | })?; |
| 859 | if lifecycle.refusal.is_none() { |
| 860 | lifecycle.refusal = load_first_refusal(dir, run_id)?; |
| 861 | } |
| 862 | Ok(Some(lifecycle)) |
| 863 | } |
| 864 | |
| 865 | fn save_lifecycle(dir: &Path, lifecycle: &ManagedLifecycle) -> CliResult<()> { |
| 866 | validate_run_id(&lifecycle.run_id)?; |