diff --git a/src/commands/mod.rs b/src/commands/mod.rs index bff6612..33086c9 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -428,11 +428,21 @@ impl FormatterValue for Screens { impl Formatter for Screens { fn format(&self, output_type: OutputType) -> String { + fn format_boolean_field(value: &serde_json::Value) -> Cell { + if value.as_bool().unwrap_or(false) { + cell!(c -> "✅") + } else { + cell!(c -> "❌") + } + } + format_value( output_type, vec![ "Id", "Name", + "Enabled", + "Priority", "Hardware Version", "In Sync", "Last Ping", @@ -441,6 +451,8 @@ impl Formatter for Screens { vec![ "id", "name", + "is_enabled", + "priority", "hardware_version", "in_sync", "last_ping", @@ -448,12 +460,8 @@ impl Formatter for Screens { ], self, Some(|field: &str, value: &serde_json::Value| { - if field.eq("in_sync") { - if value.as_bool().unwrap_or(false) { - cell!(c -> "✅") - } else { - cell!(c -> "❌") - } + if field.eq("is_enabled") || field.eq("priority") || field.eq("in_sync") { + format_boolean_field(value) } else if field.eq("uptime") { let uptime = if let Some(uptime) = value.as_u64() { indicatif::HumanDuration(Duration::new(uptime, 0)).to_string() @@ -488,12 +496,26 @@ impl FormatterValue for Playlists { impl Formatter for Playlists { fn format(&self, output_type: OutputType) -> String { + fn format_boolean_field(value: &serde_json::Value) -> Cell { + if value.as_bool().unwrap_or(false) { + cell!(c -> "✅") + } else { + cell!(c -> "❌") + } + } + format_value( output_type, - vec!["Id", "Title"], - vec!["id", "title"], + vec!["Id", "Title", "Enabled", "Priority"], + vec!["id", "title", "is_enabled", "priority"], self, - None:: Cell>, + Some(|field: &str, value: &serde_json::Value| { + if field.eq("is_enabled") || field.eq("priority") { + format_boolean_field(value) + } else { + Cell::new(value.as_str().unwrap_or("N/A")) + } + }), ) } } diff --git a/src/commands/screen.rs b/src/commands/screen.rs index 9434eec..15f32c2 100644 --- a/src/commands/screen.rs +++ b/src/commands/screen.rs @@ -178,13 +178,13 @@ mod tests { let screen = Screens::new(serde_json::from_str("[{\"id\":\"017a5104-524b-33d8-8026-9087b59e7eb5\",\"team_id\":\"016343c2-82b8-0000-a121-e30f1035875e\",\"created_at\":\"2021-06-28T05:07:55+00:00\",\"name\":\"Renat's integrated wired NM\",\"is_enabled\":true,\"coords\":[55.22931, 48.90429],\"last_ping\":\"2021-08-25T06:17:20.728+00:00\",\"last_ip\":null,\"local_ip\":\"192.168.1.146\",\"mac\":\"b8:27:eb:d6:83:6f\",\"last_screenshot_time\":\"2021-08-25T06:09:04.399+00:00\",\"uptime\": 230728,\"load_avg\":\"0.14\",\"signal_strength\":null,\"interface\":\"eth0\",\"debug\":false,\"location\":\"Kamsko-Ust'inskiy rayon, Russia\",\"team\":\"016343c2-82b8-0000-a121-e30f1035875e\",\"timezone\":\"Europe/Moscow\",\"type\":\"hardware\",\"hostname\":\"srly-4shnfrdc5cd2p0p\",\"ws_open\":false,\"status\":\"Offline\",\"last_screenshot\":\"https://us-assets.screenlyapp.com/01CD1W50NR000A28F31W83B1TY/screenshots/01F98G8MJB6FC809MGGYTSWZNN/5267668e6db35498e61b83d4c702dbe8\",\"in_sync\":false,\"software_version\":\"Screenly 2 Player\",\"hardware_version\":\"Raspberry Pi 3B\",\"config\":{\"hdmi_mode\": 34, \"hdmi_boost\": 2, \"hdmi_drive\": 0, \"hdmi_group\": 0, \"verify_ssl\": true, \"audio_output\": \"hdmi\", \"hdmi_timings\": \"\", \"overscan_top\": 0, \"overscan_left\": 0, \"use_composite\": false, \"display_rotate\": 0, \"overscan_right\": 0, \"overscan_scale\": 0, \"overscan_bottom\": 0, \"disable_overscan\": 0, \"shuffle_playlist\": false, \"framebuffer_width\": 0, \"use_composite_pal\": false, \"framebuffer_height\": 0, \"hdmi_force_hotplug\": true, \"use_composite_ntsc\": false, \"hdmi_pixel_encoding\": 0, \"play_history_enabled\": false}}, {\"id\":\"017a5104-524b-33d8-8026-9087b59e7eb6\",\"team_id\":\"016343c2-82b8-0000-a121-e30f1035875d\",\"created_at\":\"2020-06-28T05:07:55+00:00\",\"name\":\"Not Renat's integrated wired NM\",\"is_enabled\":true,\"coords\":[55.22931, 48.90429],\"last_ping\":\"2020-08-25T06:17:20.728+00:00\",\"last_ip\":null,\"local_ip\":\"192.168.1.146\",\"mac\":\"b8:27:eb:d6:83:6f\",\"last_screenshot_time\":\"2021-08-25T06:09:04.399+00:00\",\"uptime\":230728,\"load_avg\":\"0.14\",\"signal_strength\":null,\"interface\":\"eth0\",\"debug\":false,\"location\":\"Kamsko-Ust'inskiy rayon, Russia\",\"team\":\"016343c2-82b8-0000-a121-e30f1035875e\",\"timezone\":\"Europe/Moscow\",\"type\":\"hardware\",\"hostname\":\"srly-4shnfrdc5cd2p0p\",\"ws_open\":false,\"status\":\"Offline\",\"last_screenshot\":\"https://us-assets.screenlyapp.com/01CD1W50NR000A28F31W83B1TY/screenshots/01F98G8MJB6FC809MGGYTSWZNN/5267668e6db35498e61b83d4c702dbe8\",\"in_sync\":false,\"software_version\":\"Screenly 2 Player\",\"hardware_version\":\"Raspberry Pi 3B\",\"config\":{\"hdmi_mode\": 34, \"hdmi_boost\": 2, \"hdmi_drive\": 0, \"hdmi_group\": 0, \"verify_ssl\": true, \"audio_output\": \"hdmi\", \"hdmi_timings\": \"\", \"overscan_top\": 0, \"overscan_left\": 0, \"use_composite\": false, \"display_rotate\": 0, \"overscan_right\": 0, \"overscan_scale\": 0, \"overscan_bottom\": 0, \"disable_overscan\": 0, \"shuffle_playlist\": false, \"framebuffer_width\": 0, \"use_composite_pal\": false, \"framebuffer_height\": 0, \"hdmi_force_hotplug\": true, \"use_composite_ntsc\": false, \"hdmi_pixel_encoding\": 0, \"play_history_enabled\": false}}]").unwrap()); println!("{}", screen.format(OutputType::HumanReadable)); let expected_output = - "+--------------------------------------+---------------------------------+------------------+---------+-------------------------------+--------+\n\ -| Id | Name | Hardware Version | In Sync | Last Ping | Uptime |\n\ -+--------------------------------------+---------------------------------+------------------+---------+-------------------------------+--------+\n\ -| 017a5104-524b-33d8-8026-9087b59e7eb5 | Renat's integrated wired NM | Raspberry Pi 3B | ❌ | 2021-08-25T06:17:20.728+00:00 | 3 days |\n\ -+--------------------------------------+---------------------------------+------------------+---------+-------------------------------+--------+\n\ -| 017a5104-524b-33d8-8026-9087b59e7eb6 | Not Renat's integrated wired NM | Raspberry Pi 3B | ❌ | 2020-08-25T06:17:20.728+00:00 | 3 days |\n\ -+--------------------------------------+---------------------------------+------------------+---------+-------------------------------+--------+\n"; + "+--------------------------------------+---------------------------------+---------+----------+------------------+---------+-------------------------------+--------+\n\ +| Id | Name | Enabled | Priority | Hardware Version | In Sync | Last Ping | Uptime |\n\ ++--------------------------------------+---------------------------------+---------+----------+------------------+---------+-------------------------------+--------+\n\ +| 017a5104-524b-33d8-8026-9087b59e7eb5 | Renat's integrated wired NM | ✅ | ❌ | Raspberry Pi 3B | ❌ | 2021-08-25T06:17:20.728+00:00 | 3 days |\n\ ++--------------------------------------+---------------------------------+---------+----------+------------------+---------+-------------------------------+--------+\n\ +| 017a5104-524b-33d8-8026-9087b59e7eb6 | Not Renat's integrated wired NM | ✅ | ❌ | Raspberry Pi 3B | ❌ | 2020-08-25T06:17:20.728+00:00 | 3 days |\n\ ++--------------------------------------+---------------------------------+---------+----------+------------------+---------+-------------------------------+--------+\n"; assert_eq!(screen.format(OutputType::HumanReadable), expected_output); }