tldr_cli/commands/daemon/
list.rs1use clap::Args;
10use serde::Serialize;
11
12use crate::output::OutputFormat;
13
14use super::daemon_registry::{live_entries, DaemonRegistryEntry};
15
16#[derive(Debug, Clone, Args, Default)]
22pub struct DaemonListArgs {}
23
24#[derive(Debug, Serialize)]
26struct DaemonListOutput<'a> {
27 daemons: &'a [DaemonRegistryEntry],
28}
29
30impl DaemonListArgs {
31 pub fn run(&self, format: OutputFormat, quiet: bool) -> anyhow::Result<()> {
33 let entries = live_entries();
34
35 if quiet {
36 return Ok(());
37 }
38
39 match format {
40 OutputFormat::Json | OutputFormat::Compact => {
41 let out = DaemonListOutput { daemons: &entries };
42 println!("{}", serde_json::to_string_pretty(&out)?);
43 }
44 OutputFormat::Text | OutputFormat::Sarif | OutputFormat::Dot => {
45 if entries.is_empty() {
46 println!("No daemons running");
47 } else {
48 println!("PROJECT\tPID\tSOCKET\tSTARTED_AT");
49 for e in &entries {
50 println!(
51 "{}\t{}\t{}\t{}",
52 e.project.display(),
53 e.pid,
54 e.socket.display(),
55 e.started_at
56 );
57 }
58 }
59 }
60 }
61 Ok(())
62 }
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn list_args_default_constructs() {
71 let _args = DaemonListArgs::default();
72 }
73}