Skip to content

Commit 64ac10f

Browse files
committed
feat(tsfmt): clean up verbose printing
1 parent d688317 commit 64ac10f

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

lib/cli.ts

+39-13
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,51 @@ let root = commandpost
8383
}
8484

8585
if (verbose) {
86-
console.log("replace: " + (replace ? "ON" : "OFF"));
87-
console.log("verify: " + (verify ? "ON" : "OFF"));
88-
console.log("baseDir: " + (baseDir ? baseDir : process.cwd()));
89-
console.log("stdin: " + (stdin ? "ON" : "OFF"));
90-
console.log("files from tsconfig: " + (useTsconfig ? "ON" : "OFF"));
91-
console.log("tsconfig: " + (tsconfig ? "ON" : "OFF"));
86+
const printPool: { [name: string]: string; } = {};
87+
const printSetting = (name: string, value: string | boolean) => {
88+
if (typeof value === "boolean") {
89+
printPool[name] = value ? "ON" : "OFF";
90+
} else {
91+
printPool[name] = value;
92+
}
93+
};
94+
const doPrint = () => {
95+
const maxLength = Object.keys(printPool).reduce((p, c) => Math.max(p, c.length), 0);
96+
Object.keys(printPool).forEach(key => {
97+
const value = printPool[key];
98+
console.log(`${padSpaces(key, maxLength + 1)}: ${value}`);
99+
});
100+
101+
function padSpaces(str: string, len: number) {
102+
let result = str;
103+
while (result.length < len) {
104+
result += " ";
105+
}
106+
return result;
107+
}
108+
};
109+
110+
printSetting("replace", replace);
111+
printSetting("verify", verify);
112+
printSetting("baseDir", baseDir ? baseDir : process.cwd());
113+
printSetting("stdin", stdin);
114+
printSetting("files from tsconfig", useTsconfig);
115+
printSetting("tsconfig", tsconfig);
92116
if (tsconfigFile) {
93-
console.log("specified tsconfig.json: " + tsconfigFile);
117+
printSetting("specified tsconfig.json", tsconfigFile);
94118
}
95-
console.log("tslint: " + (tslint ? "ON" : "OFF"));
119+
printSetting("tslint", tslint);
96120
if (tslintFile) {
97-
console.log("specified tslint.json: " + tslintFile);
121+
printSetting("specified tslint.json", tslintFile);
98122
}
99-
console.log("editorconfig: " + (editorconfig ? "ON" : "OFF"));
100-
console.log("vscode: " + (vscode ? "ON" : "OFF"));
101-
console.log("tsfmt: " + (tsfmt ? "ON" : "OFF"));
123+
printSetting("editorconfig", editorconfig);
124+
printSetting("vscode", vscode);
125+
printSetting("tsfmt", tsfmt);
102126
if (tsfmtFile) {
103-
console.log("specified tsfmt.json: " + tsfmtFile);
127+
printSetting("specified tsfmt.json", tsfmtFile);
104128
}
129+
130+
doPrint();
105131
}
106132

107133
if (stdin) {

0 commit comments

Comments
 (0)