Skip to content

Commit 45809e7

Browse files
Merge pull request #249 from Screenly/issue_240
feat: add missing is_enabled and priority fields to CLI output
2 parents 6e4ee8e + c2a048c commit 45809e7

2 files changed

Lines changed: 38 additions & 16 deletions

File tree

src/commands/mod.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,21 @@ impl FormatterValue for Screens {
428428

429429
impl Formatter for Screens {
430430
fn format(&self, output_type: OutputType) -> String {
431+
fn format_boolean_field(value: &serde_json::Value) -> Cell {
432+
if value.as_bool().unwrap_or(false) {
433+
cell!(c -> "✅")
434+
} else {
435+
cell!(c -> "❌")
436+
}
437+
}
438+
431439
format_value(
432440
output_type,
433441
vec![
434442
"Id",
435443
"Name",
444+
"Enabled",
445+
"Priority",
436446
"Hardware Version",
437447
"In Sync",
438448
"Last Ping",
@@ -441,19 +451,17 @@ impl Formatter for Screens {
441451
vec![
442452
"id",
443453
"name",
454+
"is_enabled",
455+
"priority",
444456
"hardware_version",
445457
"in_sync",
446458
"last_ping",
447459
"uptime",
448460
],
449461
self,
450462
Some(|field: &str, value: &serde_json::Value| {
451-
if field.eq("in_sync") {
452-
if value.as_bool().unwrap_or(false) {
453-
cell!(c -> "✅")
454-
} else {
455-
cell!(c -> "❌")
456-
}
463+
if field.eq("is_enabled") || field.eq("priority") || field.eq("in_sync") {
464+
format_boolean_field(value)
457465
} else if field.eq("uptime") {
458466
let uptime = if let Some(uptime) = value.as_u64() {
459467
indicatif::HumanDuration(Duration::new(uptime, 0)).to_string()
@@ -488,12 +496,26 @@ impl FormatterValue for Playlists {
488496

489497
impl Formatter for Playlists {
490498
fn format(&self, output_type: OutputType) -> String {
499+
fn format_boolean_field(value: &serde_json::Value) -> Cell {
500+
if value.as_bool().unwrap_or(false) {
501+
cell!(c -> "✅")
502+
} else {
503+
cell!(c -> "❌")
504+
}
505+
}
506+
491507
format_value(
492508
output_type,
493-
vec!["Id", "Title"],
494-
vec!["id", "title"],
509+
vec!["Id", "Title", "Enabled", "Priority"],
510+
vec!["id", "title", "is_enabled", "priority"],
495511
self,
496-
None::<fn(&str, &serde_json::Value) -> Cell>,
512+
Some(|field: &str, value: &serde_json::Value| {
513+
if field.eq("is_enabled") || field.eq("priority") {
514+
format_boolean_field(value)
515+
} else {
516+
Cell::new(value.as_str().unwrap_or("N/A"))
517+
}
518+
}),
497519
)
498520
}
499521
}

src/commands/screen.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ mod tests {
178178
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());
179179
println!("{}", screen.format(OutputType::HumanReadable));
180180
let expected_output =
181-
"+--------------------------------------+---------------------------------+------------------+---------+-------------------------------+--------+\n\
182-
| Id | Name | Hardware Version | In Sync | Last Ping | Uptime |\n\
183-
+--------------------------------------+---------------------------------+------------------+---------+-------------------------------+--------+\n\
184-
| 017a5104-524b-33d8-8026-9087b59e7eb5 | Renat's integrated wired NM | Raspberry Pi 3B | ❌ | 2021-08-25T06:17:20.728+00:00 | 3 days |\n\
185-
+--------------------------------------+---------------------------------+------------------+---------+-------------------------------+--------+\n\
186-
| 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\
187-
+--------------------------------------+---------------------------------+------------------+---------+-------------------------------+--------+\n";
181+
"+--------------------------------------+---------------------------------+---------+----------+------------------+---------+-------------------------------+--------+\n\
182+
| Id | Name | Enabled | Priority | Hardware Version | In Sync | Last Ping | Uptime |\n\
183+
+--------------------------------------+---------------------------------+---------+----------+------------------+---------+-------------------------------+--------+\n\
184+
| 017a5104-524b-33d8-8026-9087b59e7eb5 | Renat's integrated wired NM | ✅ | ❌ | Raspberry Pi 3B | ❌ | 2021-08-25T06:17:20.728+00:00 | 3 days |\n\
185+
+--------------------------------------+---------------------------------+---------+----------+------------------+---------+-------------------------------+--------+\n\
186+
| 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\
187+
+--------------------------------------+---------------------------------+---------+----------+------------------+---------+-------------------------------+--------+\n";
188188

189189
assert_eq!(screen.format(OutputType::HumanReadable), expected_output);
190190
}

0 commit comments

Comments
 (0)