(&self)
| 47 | |
| 48 | impl Command for Show { |
| 49 | fn run(&self) -> CliResult<()> { |
| 50 | // Every form routes: the wire resolves by path and carries the |
| 51 | // stored entry's full domain bytes, so the revision hash, the |
| 52 | // JSON projection, and the --revision guard all run client-side |
| 53 | // over wire-carried data. |
| 54 | if crate::commands::rpc::vault_show(self)? { |
| 55 | return Ok(()); |
| 56 | } |
| 57 | |
| 58 | let root = find_repository_root()?; |
| 59 | let repo = |
| 60 | crate::commands::open_readonly_repository(&root).map_err(CliError::Repository)?; |
| 61 | |
| 62 | let entry = repo |
| 63 | .vault_retrieve(&self.path) |
| 64 | .map_err(CliError::Repository)? |
| 65 | .ok_or_else(|| CliError::VaultEntityNotFound { |
| 66 | kind: "vault entry", |
| 67 | id: self.path.clone(), |
| 68 | hint: None, |
| 69 | })?; |
| 70 | let revision_hash = |
| 71 | (self.json || self.revision.is_some()).then(|| vault_entry_revision_hash(&entry)); |
| 72 | if let Some(actual) = revision_hash.as_deref() { |
| 73 | require_revision(&self.path, self.revision.as_deref(), actual)?; |
| 74 | } |
| 75 | |
| 76 | if self.json { |
| 77 | let json = entry_json( |
| 78 | &self.path, |
| 79 | &entry, |
| 80 | revision_hash |
| 81 | .as_deref() |
| 82 | .expect("JSON output always computes a revision"), |
| 83 | ); |
| 84 | println!("{}", serde_json::to_string_pretty(&json).unwrap()); |
| 85 | } else { |
| 86 | print!("{}", String::from_utf8_lossy(&entry.content_bytes)); |
| 87 | } |
| 88 | |
| 89 | Ok(()) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | pub(crate) fn require_revision(path: &str, expected: Option<&str>, actual: &str) -> CliResult<()> { |
nothing calls this directly
no test coverage detected