spotify_cli/output/
cache.rs1use serde::Serialize;
3
4use crate::domain::cache::CacheStatus;
5use crate::error::Result;
6
7pub fn status_human(status: CacheStatus) -> Result<()> {
8 println!(
9 "cache_root={} devices={} playlists={}",
10 status.root, status.device_count, status.playlist_count
11 );
12 Ok(())
13}
14
15#[derive(Serialize)]
16struct CacheStatusPayload {
17 root: String,
18 device_count: usize,
19 playlist_count: usize,
20}
21
22pub fn status_json(status: CacheStatus) -> Result<()> {
23 let payload = cache_status_payload(status);
24 println!("{}", serde_json::to_string(&payload)?);
25 Ok(())
26}
27
28fn cache_status_payload(status: CacheStatus) -> CacheStatusPayload {
29 CacheStatusPayload {
30 root: status.root,
31 device_count: status.device_count,
32 playlist_count: status.playlist_count,
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use super::cache_status_payload;
39 use crate::domain::cache::CacheStatus;
40
41 #[test]
42 fn cache_status_payload_shape() {
43 let payload = cache_status_payload(CacheStatus {
44 root: "/tmp".to_string(),
45 device_count: 1,
46 playlist_count: 2,
47 });
48 assert_eq!(payload.device_count, 1);
49 assert_eq!(payload.playlist_count, 2);
50 }
51}