(args: &crate::commands::log::command::Log)
| 295 | // --------------------------------------------------------------------------- |
| 296 | |
| 297 | pub fn log(args: &crate::commands::log::command::Log) -> CliResult<bool> { |
| 298 | let Some(session) = Service::open()? else { |
| 299 | return Ok(false); |
| 300 | }; |
| 301 | let request = pb::LogRequest { |
| 302 | repository: Some(session.reference.clone()), |
| 303 | all_views: args.all, |
| 304 | view: args.view.clone(), |
| 305 | cursor: None, |
| 306 | budget: args.count.map(|count| pb::PageBudget { |
| 307 | max_items: Some(count as u32), |
| 308 | max_bytes: None, |
| 309 | }), |
| 310 | path_filter: args.path.clone().into_iter().collect(), |
| 311 | tags_only: args.tags_only, |
| 312 | }; |
| 313 | let response = session.log(request)?; |
| 314 | |
| 315 | let mut entries = response.entries; // the wire carries newest-first |
| 316 | if args.reverse { |
| 317 | entries.reverse(); // --reverse: oldest first |
| 318 | } |
| 319 | |
| 320 | // Same renders as the local path: the versioned pretty JSON array for |
| 321 | // -f json, and the styled default format (hash === markers, (tag) |
| 322 | // marker, blank line between entries) otherwise. |
| 323 | use crate::commands::log::types::{JsonAuthor, JsonLogEntry, LogFormat}; |
| 324 | if matches!(args.effective_format(), LogFormat::Json) { |
| 325 | let json_entries: Vec<JsonLogEntry> = entries |
| 326 | .iter() |
| 327 | .map(|entry| JsonLogEntry { |
| 328 | sequence: entry.sequence, |
| 329 | hash: wire_hash_base32(&entry.hash), |
| 330 | state: wire_hash_base32(&entry.state), |
| 331 | message: entry.message.clone(), |
| 332 | description: entry.description.clone(), |
| 333 | authors: entry |
| 334 | .authors |
| 335 | .iter() |
| 336 | .map(|author| JsonAuthor { |
| 337 | name: author.name.clone(), |
| 338 | email: author.email.clone(), |
| 339 | }) |
| 340 | .collect(), |
| 341 | timestamp: entry.recorded_at.as_ref().and_then(|ts| { |
| 342 | chrono::DateTime::from_timestamp(ts.seconds, ts.nanos.max(0) as u32) |
| 343 | .map(|time| time.to_rfc3339()) |
| 344 | }), |
| 345 | is_tagged: entry.is_tagged, |
| 346 | }) |
| 347 | .collect(); |
| 348 | let doc = serde_json::to_string_pretty(&json_entries) |
| 349 | .map_err(|e| CliError::Internal(e.into()))?; |
| 350 | println!("{doc}"); |
| 351 | return Ok(true); |
| 352 | } |
| 353 | |
| 354 | use crate::commands::{format_hash_with_length, format_timestamp}; |
no test coverage detected