⚙️ Add hideFileSize option and update tree.ts script logic
This commit is contained in:
@@ -22,6 +22,7 @@ const defaultSkipDirs = [
|
||||
interface ListDirOptions {
|
||||
maxDepth: number;
|
||||
hideMoreDirs: boolean;
|
||||
hideFileSize: boolean;
|
||||
}
|
||||
|
||||
async function listDir(
|
||||
@@ -38,19 +39,17 @@ async function listDir(
|
||||
const fullName = joinPath(dir, dirEntry.name);
|
||||
if (dirEntry.isDirectory) {
|
||||
const showNextDepth = (depth + 1) <= options.maxDepth;
|
||||
if (!options.hideMoreDirs) {
|
||||
console.log(
|
||||
`${tab}- [${dirEntry.name}]${
|
||||
showNextDepth
|
||||
? ""
|
||||
: term.auto(
|
||||
"[blue][[[ \t[...more dirs...]]]][/]",
|
||||
)
|
||||
}`,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
`${tab}- [${dirEntry.name}]${
|
||||
showNextDepth
|
||||
? ""
|
||||
: (options.hideMoreDirs ? "" : term.auto(
|
||||
"[blue][[[ \t[...more dirs...]]]][/]",
|
||||
))
|
||||
}`,
|
||||
);
|
||||
if (showNextDepth) {
|
||||
await listDir(fullName, depth + 1, options.maxDepth);
|
||||
await listDir(fullName, depth + 1, options);
|
||||
}
|
||||
} else {
|
||||
let fileDesc = "";
|
||||
@@ -68,11 +67,13 @@ async function listDir(
|
||||
);
|
||||
}
|
||||
}
|
||||
console.log(
|
||||
`${tab}- ${
|
||||
term.auto("[green][[[" + dirEntry.name + "]]][/]")
|
||||
} \t${fileDesc}`,
|
||||
);
|
||||
let fileLn = `${tab}- ${
|
||||
term.auto("[green][[[" + dirEntry.name + "]]][/]")
|
||||
}`;
|
||||
if (!options.hideFileSize) {
|
||||
fileLn += ` \t${fileDesc}`;
|
||||
}
|
||||
console.log(fileLn);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -82,7 +83,7 @@ async function listDir(
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const flags = parseArgs(Deno.args, {
|
||||
boolean: ["help", "hide-more-dirs"],
|
||||
boolean: ["help", "hide-more-dirs", "hide-file-size"],
|
||||
number: ["depth"],
|
||||
});
|
||||
if (flags.help) {
|
||||
@@ -98,6 +99,7 @@ tree.ts [parameters] <dir>
|
||||
|
||||
const maxDepth = parseIntVal(flags.depth, 10);
|
||||
const hideMoreDirs = flags["hide-more-dirs"];
|
||||
const hideFileSize = flags["hide-file-size"];
|
||||
|
||||
let baseDir = ".";
|
||||
if (flags._.length > 0) {
|
||||
@@ -106,10 +108,11 @@ tree.ts [parameters] <dir>
|
||||
await listDir(baseDir, 0, {
|
||||
maxDepth,
|
||||
hideMoreDirs,
|
||||
hideFileSize,
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((e) => log.error(e));
|
||||
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260411T093048+08:00.MEUCIQDmZojbZR+wufhjkUbn
|
||||
// UpciHPInFK+T7/F4u1pYzmfuOQIgOLnp7oKSmRQOqHo3XvP+wzZYMLAMAHanA+Q5iuODPLQ=
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260411T094252+08:00.MEUCIFfZBs0de3SZZtVCpAZ6
|
||||
// Kxb5dnBCiwjGOTqydRtCl8CLAiEA/4W5N784C0FkcFpkYUB6vdLecJ7wsFFfNeO95AFiDew=
|
||||
|
||||
Reference in New Issue
Block a user