Skip to content

Commit 26c0d9c

Browse files
committed
updated
1 parent b55455a commit 26c0d9c

File tree

2 files changed

+195
-278
lines changed

2 files changed

+195
-278
lines changed

bin/rdap-validator

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env node
22

3+
process.stdout.say = (l) => process.stdout.write(l + "\n");
4+
35
/**
46
* start by parsing the command-line arguments
57
*/
@@ -43,27 +45,32 @@ const jsonResultData = {
4345

4446
rdapValidator.setXHR(XMLHttpRequest.XMLHttpRequest);
4547

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";
4754

4855
const cliResultCallback = function(result, message, path) {
49-
const indentString = " ";
5056
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)) + "- ";
5259

5360
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 + ")");
5762

5863
} else if (false === onlyErrors) {
5964
if (true === result) {
60-
console.log(indent + "\x1b[1;32m✓\x1b[0m " + message);
65+
process.stdout.say(indent + MSG_PASS + " " + message);
6166

6267
} else {
63-
console.log(indent + "\x1b[1;33mi\x1b[0m " + message);
68+
process.stdout.say(indent + MSG_INFO + " " + message);
6469

6570
}
6671
}
72+
73+
lastDepth = depth;
6774
};
6875

6976
const jsonResultCallback = function(result, message, path) {
@@ -81,7 +88,7 @@ if (opt.named.json) {
8188
jsonResultData.responseHeaders = rdapValidator.lastTestedResponseHeaders;
8289
jsonResultData.jsonResponse = rdapValidator.lastTestedResponse;
8390

84-
console.log(JSON.stringify(jsonResultData, null, 2));
91+
process.stdout.say(JSON.stringify(jsonResultData, null, 2));
8592
});
8693

8794
rdapValidator.setResultCallback(jsonResultCallback);
@@ -92,23 +99,23 @@ if (opt.named.json) {
9299
}
93100

94101
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:");
97104

98-
console.log(" --help Show this help.");
105+
process.stdout.say(" --help Show this help.");
99106

100-
console.log(" --only-errors Only show errors.");
107+
process.stdout.say(" --only-errors Only show errors.");
101108

102-
console.log(" --json Output result in JSON.");
109+
process.stdout.say(" --json Output result in JSON.");
103110

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));
106113

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));
109116

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>.");
112119

113120
process.exit(x);
114121
}

0 commit comments

Comments
 (0)