upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grasp-audit/src/bin/grasp-audit.rs30
1 files changed, 22 insertions, 8 deletions
diff --git a/grasp-audit/src/bin/grasp-audit.rs b/grasp-audit/src/bin/grasp-audit.rs
index e77a698..a6db627 100644
--- a/grasp-audit/src/bin/grasp-audit.rs
+++ b/grasp-audit/src/bin/grasp-audit.rs
@@ -67,13 +67,25 @@ enum Commands {
67 67
68#[tokio::main] 68#[tokio::main]
69async fn main() -> Result<()> { 69async fn main() -> Result<()> {
70 // Initialize logging 70 // In JSON mode logs must not pollute stdout (used for machine-readable output).
71 tracing_subscriber::fmt() 71 // Check argv directly so we know the mode before parsing the full CLI.
72 .with_env_filter( 72 let json_mode = std::env::args().any(|a| a == "--json");
73 tracing_subscriber::EnvFilter::from_default_env() 73 if json_mode {
74 .add_directive(tracing::Level::INFO.into()), 74 tracing_subscriber::fmt()
75 ) 75 .with_env_filter(
76 .init(); 76 tracing_subscriber::EnvFilter::from_default_env()
77 .add_directive(tracing::Level::INFO.into()),
78 )
79 .with_writer(std::io::stderr)
80 .init();
81 } else {
82 tracing_subscriber::fmt()
83 .with_env_filter(
84 tracing_subscriber::EnvFilter::from_default_env()
85 .add_directive(tracing::Level::INFO.into()),
86 )
87 .init();
88 }
77 89
78 let cli = Cli::parse(); 90 let cli = Cli::parse();
79 91
@@ -99,7 +111,9 @@ async fn main() -> Result<()> {
99 if let Some(interval) = watch { 111 if let Some(interval) = watch {
100 let mut run = 1u64; 112 let mut run = 1u64;
101 loop { 113 loop {
102 println!("\n[Run {}]", run); 114 if !json {
115 println!("\n[Run {}]", run);
116 }
103 let report = 117 let report =
104 grasp_audit::probe::run_probe(&relay, keys.clone(), read_only, timeout) 118 grasp_audit::probe::run_probe(&relay, keys.clone(), read_only, timeout)
105 .await; 119 .await;