@@ -2,11 +2,9 @@ use std::process;
22use trust_dns_client:: rr:: RecordType ;
33
44use clap:: Parser ;
5- use colored:: * ;
6- use log:: trace;
75use miette:: Result ;
86
9- use digs:: { cli, cli:: Opts , config , dns , utils} ;
7+ use digs:: { cli, cli:: Opts , output :: Printer , utils} ;
108
119fn run ( ) -> Result < ( ) > {
1210 let opts = Opts :: parse ( ) ;
@@ -21,55 +19,9 @@ fn run() -> Result<()> {
2119 cli:: RecordType :: SOA => RecordType :: SOA ,
2220 cli:: RecordType :: TXT => RecordType :: TXT ,
2321 } ;
24- let config = config:: read ( & opts. config ) ?;
25-
26- for server in config. servers {
27- let response = dns:: query ( & domain, record_type, & server. ip ) ;
28- trace ! ( "Response -> {:?}" , response) ;
29-
30- println ! ( "{}" , server. name) ;
31- match response {
32- Err ( e) => {
33- println ! ( " {}" , e. to_string( ) . red( ) ) ;
34- }
35- Ok ( res) => {
36- let print_output = |rr_type : String , name : String , rdata : String | {
37- println ! (
38- " {} {} {}" ,
39- rr_type. green( ) . bold( ) ,
40- name. blue( ) ,
41- rdata. bold( )
42- ) ;
43- } ;
44-
45- // FIXME
46- if !res. answers ( ) . is_empty ( ) {
47- for res in res. answers ( ) {
48- let rr_type = res. rr_type ( ) . to_string ( ) ;
49- print_output (
50- rr_type,
51- res. name ( ) . to_string ( ) ,
52- res. data ( ) . expect ( "no `rdata` found" ) . to_string ( ) ,
53- ) ;
54- }
55- } else if res. answers ( ) . is_empty ( ) && !res. name_servers ( ) . is_empty ( ) {
56- // if answers is empty, print default record (SOA)
57- for res in res. name_servers ( ) {
58- let rr_type = res. rr_type ( ) . to_string ( ) ;
59- print_output (
60- rr_type,
61- res. name ( ) . to_string ( ) ,
62- res. data ( ) . expect ( "no `rdata` found" ) . to_string ( ) ,
63- ) ;
64- }
65- } else {
66- // if default doesn't exist
67- println ! ( "{}" , " No zone found" . to_string( ) . red( ) ) ;
68- }
69- }
70- }
71- }
7222
23+ let printer = Printer :: new ( domain, record_type, opts. config ) ;
24+ printer. print ( ) ?;
7325 Ok ( ( ) )
7426}
7527
0 commit comments