A tiny Kotlin DSL to pretty-print hierarchies of directories and files.
val hierarchy = directory {
directory("featureOne") {
file("build.gradle.kts")
}
directory("featureTwo") {
file("build.gradle.kts")
}
directory("gradle-common") {
file("build.gradle.kts")
// optional shorthand form for multiple nested directories
directory("src", "main", "kotlin") {
directory("com", "sample", "gradle") {
// optional shorthand form for a single file in one or more nested directories
file("android", "library.gradle.kts")
file("jacoco", "android.gradle.kts")
file("sonarqube", "android.gradle.kts")
}
}
}
}
println(hierarchy)
├── featureOne
│ ╰── build.gradle.kts
├── featureTwo
│ ╰── build.gradle.kts
╰── gradle-common
├── build.gradle.kts
╰── src
╰── main
╰── kotlin
╰── com
╰── sample
╰── gradle
├── android
│ ╰── library.gradle.kts
├── jacoco
│ ╰── android.gradle.kts
╰── sonarqube
╰── android.gradle.kts
Additional configuration can be specified by passing a DirectoryContext
to the top-level directory
function.
directory(
context = DirectoryContext(
separators = Separators(
empty = " ",
pipe = "│ ",
split = "├── ",
corner = "╰── ",
),
sortMode = SortMode.NONE,
directoriesFirst = false,
compactMode = CompactMode.NONE,
)
) {
file("file.txt")
}
Customize separators.
|
|
|
|
|
|
NONE
- Do not sort.ASC
- Sort ascending by file/directory names.DESC
- Sort descending by file/directory names.
|
|
|
|
|
|
false
- Do not reorganize files/directories.true
- Place directories before files.
|
|
|
|
NONE
- No directories and files will be merged and each will display on a separate line.EXACT
- Directories and files defined in a single call todirectory
orfile
will be merged.DIRECTORIES
- Directories with no sibling directories or files will be merged with their parents.ALL
- Directories and files with no sibling directories or files will be merged with their parents.
directory(
DirectoryContext(compactMode = compactMode)
) {
directory("one") {
file("two", "file.txt")
}
}
|
|
|
|
|
|
|
|
The library is available from the MavenCentral repository as a Kotlin Multiplatform library targeting JVM, JS and native:
implementation("io.github.antimonit:directory-tree:1.3.0")