1
1
#!/usr/bin/env node
2
2
3
+ process . stdout . say = ( l ) => process . stdout . write ( l + "\n" ) ;
4
+
3
5
/**
4
6
* start by parsing the command-line arguments
5
7
*/
@@ -43,27 +45,32 @@ const jsonResultData = {
43
45
44
46
rdapValidator . setXHR ( XMLHttpRequest . XMLHttpRequest ) ;
45
47
46
- let lastPath = null ;
48
+ let lastDepth = 0 ;
49
+
50
+ const INDENT_STRING = " " ;
51
+ const MSG_FAIL = "\x1b[1;31m✘\x1b[0m" ;
52
+ const MSG_PASS = "\x1b[1;32m✓\x1b[0m" ;
53
+ const MSG_INFO = "\x1b[1;33mi\x1b[0m" ;
47
54
48
55
const cliResultCallback = function ( result , message , path ) {
49
- const indentString = " " ;
50
56
const onlyErrors = opt . named . hasOwnProperty ( "only-errors" ) ;
51
- const indent = indentString . repeat ( onlyErrors ? 0 : Math . max ( 0 , rdapValidator . path . length - 1 ) ) ;
57
+ const depth = rdapValidator . path . length ;
58
+ const indent = INDENT_STRING . repeat ( onlyErrors ? 0 : Math . max ( 0 , depth - 1 ) ) + "- " ;
52
59
53
60
if ( false === result ) {
54
- message = message + " (" + path + ")" ;
55
-
56
- console . log ( indent + "\x1b[1;31m✘\x1b[0m " + message ) ;
61
+ process . stdout . say ( indent + MSG_FAIL + " " + message + " (" + path + ")" ) ;
57
62
58
63
} else if ( false === onlyErrors ) {
59
64
if ( true === result ) {
60
- console . log ( indent + "\x1b[1;32m✓\x1b[0m " + message ) ;
65
+ process . stdout . say ( indent + MSG_PASS + " " + message ) ;
61
66
62
67
} else {
63
- console . log ( indent + "\x1b[1;33mi\x1b[0m " + message ) ;
68
+ process . stdout . say ( indent + MSG_INFO + " " + message ) ;
64
69
65
70
}
66
71
}
72
+
73
+ lastDepth = depth ;
67
74
} ;
68
75
69
76
const jsonResultCallback = function ( result , message , path ) {
@@ -81,7 +88,7 @@ if (opt.named.json) {
81
88
jsonResultData . responseHeaders = rdapValidator . lastTestedResponseHeaders ;
82
89
jsonResultData . jsonResponse = rdapValidator . lastTestedResponse ;
83
90
84
- console . log ( JSON . stringify ( jsonResultData , null , 2 ) ) ;
91
+ process . stdout . say ( JSON . stringify ( jsonResultData , null , 2 ) ) ;
85
92
} ) ;
86
93
87
94
rdapValidator . setResultCallback ( jsonResultCallback ) ;
@@ -92,23 +99,23 @@ if (opt.named.json) {
92
99
}
93
100
94
101
function help ( x ) {
95
- console . log ( "Usage: " + process . argv [ 1 ] + " [OPTIONS] URL" ) ;
96
- console . log ( "Options:" ) ;
102
+ process . stdout . say ( "Usage: " + process . argv [ 1 ] + " [OPTIONS] URL" ) ;
103
+ process . stdout . say ( "Options:" ) ;
97
104
98
- console . log ( " --help Show this help." ) ;
105
+ process . stdout . say ( " --help Show this help." ) ;
99
106
100
- console . log ( " --only-errors Only show errors." ) ;
107
+ process . stdout . say ( " --only-errors Only show errors." ) ;
101
108
102
- console . log ( " --json Output result in JSON." ) ;
109
+ process . stdout . say ( " --json Output result in JSON." ) ;
103
110
104
- console . log ( " --type=TYPE Expected response type, which must be one of:" ) ;
105
- Object . keys ( rdapValidator . responseTypes ) . forEach ( ( t ) => console . log ( " " . repeat ( 25 ) + "- " + t ) ) ;
111
+ process . stdout . say ( " --type=TYPE Expected response type, which must be one of:" ) ;
112
+ Object . keys ( rdapValidator . responseTypes ) . forEach ( ( t ) => process . stdout . say ( " " . repeat ( 25 ) + "- " + t ) ) ;
106
113
107
- console . log ( " --server-type=TYPE Server type, which must be one of:" ) ;
108
- Object . keys ( rdapValidator . serverTypes ) . forEach ( ( t ) => console . log ( " " . repeat ( 25 ) + "- " + t ) ) ;
114
+ process . stdout . say ( " --server-type=TYPE Server type, which must be one of:" ) ;
115
+ Object . keys ( rdapValidator . serverTypes ) . forEach ( ( t ) => process . stdout . say ( " " . repeat ( 25 ) + "- " + t ) ) ;
109
116
110
- console . log ( "" ) ;
111
- console . log ( "Copyright 2024 Gavin Brown <https://about.rdap.org>." ) ;
117
+ process . stdout . say ( "" ) ;
118
+ process . stdout . say ( "Copyright 2024 Gavin Brown <https://about.rdap.org>." ) ;
112
119
113
120
process . exit ( x ) ;
114
121
}
0 commit comments