From 4e5cd51482ea69da364ff92101e5286e9e7a817d Mon Sep 17 00:00:00 2001 From: azzam Date: Fri, 16 Apr 2021 06:50:49 +0700 Subject: [PATCH] fix: tell user if no zone found If the target record is not found, show the default record (SOA). Otherwise, it's no zone. --- CHANGELOG.md | 2 ++ src/main.rs | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9364e6b..2866d3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ Unreleased changes. Release notes have not yet been written. +- tell user if no zone found + # 0.1.5 (2021-04-08) This release include fixes for creates.io workflow. diff --git a/src/main.rs b/src/main.rs index 1fb746c..bde1869 100755 --- a/src/main.rs +++ b/src/main.rs @@ -48,13 +48,20 @@ fn run() -> Result<()> { ); }; - for res in res.answers() { - let rr_type = res.rr_type().to_string(); - print_output(rr_type, res.name().to_string(), res.rdata().to_string()); - } - for res in res.name_servers() { - let rr_type = res.rr_type().to_string(); - print_output(rr_type, res.name().to_string(), res.rdata().to_string()); + if !res.answers().is_empty() { + for res in res.answers() { + let rr_type = res.rr_type().to_string(); + print_output(rr_type, res.name().to_string(), res.rdata().to_string()); + } + } else if res.answers().is_empty() && !res.name_servers().is_empty() { + // if answers is empty, print default record (SOA) + for res in res.name_servers() { + let rr_type = res.rr_type().to_string(); + print_output(rr_type, res.name().to_string(), res.rdata().to_string()); + } + } else { + // if default doesn't exist + println!("{}", " No zone found".to_string().red()); } } }